I want dropdown in User sign up form which will set the user role which belongs to a department. Here is are models
class Department < ActiveRecord::Base
has_many :roles
end
class Role < ActiveRecord::Base
belongs_to :department
has_many :users
end
class User < ActiveRecord::Base
belongs_to :roles
end
And in the registration form i am trying this:
=form.grouped_collection_select(:user, :role_id, @departments, :roles, :title, :id,:title)
This produces error undefined method `merge' for :title:Symbol
Department and Role both models contain "title"
I don't know where i am lacking
Your code should work fine if you removed the form from form.grouped_collection_select
OR
If you really need it and the form is already referring to a user form builder then you can skip the first argument of :user passed to the grouped_collection_from method
Using any form builder to initiate a helper method like (select,collection, grouped_collection, ...etc) will automatically passes its object
to the helper and the helper will expect arguments starting after the object
parameter.
Check this SO question: collection_select method gives error in Rails 3.1.1