Ruby on Rails using sorting on each of them

I am trying to use sorting for each of them. I get an error

wrong number of arguments (1 to 0)

I understand that I cannot tie them together. Does anyone know other ways to do this.

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

As a result, I want all categories to be listed from a to z.

+4
source share
1 answer

Assuming that Categoryis Active Record, then

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

+6
source

Source: https://habr.com/ru/post/1524215/


All Articles