stemitchell91
stemitchell91

Reputation: 77

Rails collection_select, wrong number of arguments

I'm trying to use a collection_select to assign a branch_id to a visit (in a form where a user books a visit with a branch) but I'm getting the error "wrong number of arguments (7 for 4..6)".

I've been using the documentation here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select And as far as I can see, my code matches the example.

Here is my 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

Upvotes: 2

Views: 1053

Answers (1)

Pavan
Pavan

Reputation: 33552

This line

<%= f.collection_select(:visit, :branch_id, Branch.all, :id, :branch_name_select, {prompt: "Select the Branch/Service"}, {:required => true}) %>

should be

<%= f.collection_select(:branch_id, Branch.all, :id, :branch_name_select, {prompt: "Select the Branch/Service"}, {:required => true}) %>

Upvotes: 4

Related Questions