Ruby on Rails: how to sort data in an array of active record objects right before iterating?

Posted by DerNalia on Stack Overflow See other posts from Stack Overflow or by DerNalia
Published on 2010-12-26T23:52:06Z Indexed on 2010/12/26 23:53 UTC
Read the original article Hit count: 187

Filed under:

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails