<%= render :partial => 'event', :collection => @events.sort_by(&:event_at)%>
This code shows a collection ordered as ASC, but i want to order this collection as DESC.
How can I achieve this?
<%= render :partial => 'event', :collection => @events.sort_by(&:event_at)%>
This code shows a collection ordered as ASC, but i want to order this collection as DESC.
How can I achieve this?
I wanted to display a league table and order by points desc. After trying out several unsuccesful methods this is what worked for me in this instance. I added this line to my controllers index method.
@teams = Team.all.order(points: :desc)
In views/sources/show.html.erb the following <%= render @source.docs.order(page_no: :asc) %> works in Rails 6.
This calls _doc.html.erb which contains
<li>
<%= doc.content %> (p. <%= doc.page_no %>)
<span class="btn btn-outline-success btn-xs"><%= link_to 'Show', doc %></span>
<span class="btn btn-outline-warning btn-xs"><%= link_to 'Edit', edit_doc_path(doc) %></span>
</li>
Rails magic! An ordered list containing selected fields of docs that reference a source. And can click to edit or view the entire doc.
Thank you. One of the answers here pointed me in the sorting part.