Using the solution of my previous question: Rails: Create a new entry in a model that belongs_to two other models, I would like to display all the opinions collected by a store.
To recap, I have a Store that has_many Products that have_many Opinions (see the previous link to have more details about models code)
In order to get all the opinions collected by a store, I use the following code in the OpinionsController:
# Show a specific store opinions.
def show
@store = Store.find_by_id params[:store_id]
end
And then, in the show.html.haml view, I use this code to display the opinions:
%table
- @store.opinions.each do |opinion|
%tr
%td= opinion.id
%td= opinion.content
%td= opinion.product.name
%td= opinion.created_at
What can I do to order opinions by opinion.created_at, no matter what the parent product is?
More generally, how to order using a parameter from the second generation child association?
Thanks in advance.