【发布时间】:2016-01-03 05:57:25
【问题描述】:
我正在尝试在 Rails 4 中制作应用程序。
我有一个行业模型。
我正在尝试对行业进行索引,并按字母顺序列出。
我有一个行业.rb:
scope :alphabetically, order("sector ASC")
我有一个索引控制器:
def index
@industries = Industry.alphabetically
end
在我的索引视图中,我有:
<% @industries.each do |industry| %>
<tr>
<td><%= image_tag industry.icon.tiny.url %></td>
<td><%= industry.sector %></td>
<td><%= link_to 'Show', industry %></td>
<td><%= link_to 'Edit', edit_industry_path(industry) %></td>
<td><%= link_to 'Destroy', industry, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
当我尝试这个时,我得到了这个错误:
ArgumentError in IndustriesController#index
The scope body needs to be callable.
如何使范围“可调用”?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 activerecord scope