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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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
issue:

<% @last_update = Comment.find(:first, :order => 'added desc',
:conditions => ["issue_id = ?", 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,

Chris
This topic is locked and can not be replied to.