Ruby on Rails: how to sort data in an array of active record objects right before iterating?
- by DerNalia
What is the best way to sort an array of active record objects by by a field?
This array is a field of an object, link_pages, and I want it sorted by the field "sequence"
<% @menu_bar.link_pages.each do |lp| %>
<li id="page_<%= lp.id%>" class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<font size=5><%= lp.name %></font> |
<%= link_to "remove",
:controller => "admin/menu_bars",
:action => :remove_page_from_menu,
:page => lp.id,
:id => @menu_bar.id %>
</li>
<% end %>
maybe there is a way to do @menu_bar.link_pages.sort_by_sequence.each do .... that would be slick... but I just don't know.