Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails, Using sort on each do

I'm trying to use sort on each do. I get the error

wrong number of arguments(1 for 0)

I understand that I cannot daisy chain them together. Does anyone know another methods of getting this done.

  <% Category.sort(:id).limit(4).each do |type| %>
      <%= type.name %>
  <% end %>

The result I am aiming for is to have all categories listed from a to z.

like image 717
Lesly Revenge Avatar asked Jan 29 '14 05:01

Lesly Revenge


1 Answers

Assuming the Category is an Active Record then

<% Category.order(:id).limit(4).each do |type| %> would do the trick.

like image 107
Pavan Avatar answered Oct 06 '22 12:10

Pavan