【发布时间】:2016-01-03 06:39:04
【问题描述】:
我正在尝试在 Rails 4 中制作应用程序。
我使用简单的表单。
我有一个行业模型。
industry.rb 有:
scope :alphabetically, -> { order("sector ASC") }
行业控制者有:
def index
#@industries = Industry.all
@industries = Industry.alphabetically
end
行业形态有:
<%= simple_form_for(@industry) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.select :sector, options_from_collection_for_select(Industry.alphabetical), :prompt => 'Select' %>
<%= f.input :icon, as: :file, :label => "Add an icon" %>
</div>
<div class="form-actions">
<%= f.button :submit, "Submit", :class => 'formsubmit' %>
</div>
<% end %>
我正在尝试为 :sector 获取表单输入以使用行业集合(通过调用范围)。
当我尝试这个时,我收到以下错误:
undefined method `alphabetical' for #<Class:0x007fef65635220>
谁能看出问题所在?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 collections scope simple-form