Sorting in html.erb

572 Views Asked by At

This code grabs information from yaml files and outputs them in ascending order (I'm assuming by default). I can't figure out how to code this to reverse the order. Any suggestions? The site is using Middleman and ERB as templating language.

View:

<ul class="app-list">
  <% data.apps.each do |app| %>
    <% if app[1][:categories][:featured] && app[1][:categories][:script] %>
      <li>
        <%= partial 'partials/app', locals: { app: app[1] } %>
      </li>
    <% end %>
  <% end %>
</ul>
1

There are 1 best solutions below

2
On

Try:

<ul class="app-list">
  <% data.apps.reverse.each do |app| %>
    <% if app[1][:categories][:featured] && app[1][:categories][:script] %>
      <li>
        <%= partial 'partials/app', locals: { app: app[1] } %>
      </li>
    <% end %>
  <% end %>
</ul>