我正在尝试使用collection_select将branch_id分配给访问(以用户预订分支访问的形式)但我收到的错误是“错误的参数数量(7为4 ... 6)”。
我一直在使用这里的文档:http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select据我所知,我的代码与示例匹配。
这是我的collection_select:
<div class="field">
<%= f.label :branch_id, "Please Pick Service Provider/Branch you would like to visit:" %><br>
<%= f.collection_select(:visit, :branch_id, Branch.all, :id, :branch_name_select, {prompt: "Select the Branch/Service"}, {:required => true}) %>
</div>
branch.rb:
class Branch < ActiveRecord::Base
belongs_to :user
has_many :visits
def branch_name_select
"#{branch_name}, #{address_line_1}, #{address_line_2}, #{city}, #{postcode}"
end
end
visit.rb:
class Visit < ActiveRecord::Base
belongs_to :branch
belongs_to :user #:as => 'created_by'
validates_uniqueness_of :time_from, :scope => [:date_from, :location], :message=>"slot is already taken on selected date"
end
答案 0 :(得分:4)
这一行
<%= f.collection_select(:visit, :branch_id, Branch.all, :id, :branch_name_select, {prompt: "Select the Branch/Service"}, {:required => true}) %>
应该是
<%= f.collection_select(:branch_id, Branch.all, :id, :branch_name_select, {prompt: "Select the Branch/Service"}, {:required => true}) %>