Forum: Ruby on Rails Add extra data to objects in an instance variable?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7bbc5c78011f20a36ee0cffa15b575ef?d=identicon&s=25 Chris Birkinshaw (Guest)
on 2006-04-28 13:30

I am building an issue log with models:

issues (belongs_to :user, has_many :comments)
comments (belongs_to :issues, belongs_to :user)
users (has_many :comments, has_many :issues)

In the list view for the issues I wanted to print the time it was last
updated. This should come from the most recent comment added, or if
there are no comments added we fall back to the creation time of the

<% @last_update = Comment.find(:first, :order => 'added desc',
:conditions => ["issue_id = ?",]) %>

<% if @last_update %>
   <%= @last_update.added %>
<% else %>
   <%= issue.added %>
<% end %>

This all works fine, however I now want to order by this data in the
paginator. I assume that I need to run though a loop adding some data to
all the objects in the @issues = Issue.find_all instance variable in the
list part of the issues controller, but how do I do this?

Best regards,

This topic is locked and can not be replied to.