简体   繁体   English

Ruby on Rails,每个都使用sort

[英]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) 错误的参数个数(1表示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. 我的目标是从a到z列出所有类别。

Assuming the Category is an Active Record then 假设CategoryActive Record

<% Category.order(:id).limit(4).each do |type| %> <% Category.order(:id).limit(4).each do |type| %> would do the trick. <% Category.order(:id).limit(4).each do |type| %>会做的伎俩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM