11175
(-- --)
February 9, 2009, 10:15am
1
Can't quite figure this one,
I have a School (has_many reviews) and a Review (belongs_to school).
I'm rendering my reviews per school like this "@School.reviews "
Which renders the "_review.html.erb" multiple times for reviews of that
school (works a treat).
But how do I control the order in which these are displayed (I'd like to
reverse them basically most recent on top).
bb.
MaD
(MaD)
February 9, 2009, 10:46am
2
this should work:
@school.reviews.sort_by { |cc| - cc.updated_at.to_i }
class School < AR
has_many :reviews, :order => 'created_at DESC'
end
class Review < AR
belongs_to :school
end
If you use @school.reviews you'll get the desired effect....
MaD escribió:
You could use named_scope to get more complexity. I think that's a possibility.
bingo bob escribió:
Alan_Brown
(Alan Brown)
February 9, 2009, 4:59pm
5
Bob,
You could also render it with jquery or some javascript library that
enables you to write the set of reviews once to javascript and present
and re-present in multiple ways as needed without more roundtrips to
the server.
Al