Ok so i have my users_controller update action with has this code and this is in production and working and i want to know what this line is doing
@user.attributes = { 'role_ids' => [] }.merge(params[:user])
and I dont understand how this is setting the role_ids and if there is a better way to do this
@user is the User and .attributes doesnt have role_ids in it so how does this work ….here is my relationships
class Role < ActiveRecord::Base
has_many :users, :through => :role_users
has_many :role_users
class User < ActiveRecord::Base
has_many :roles, :through => :role_users
has_many :role_users
class RoleUser < ActiveRecord::Base
belongs_to :role
belongs_to :user
end
and the params are
Parameters: {"utf8"=>"✓", "authenticity_token"=>"GV/BbOZdKn7SkzD8zydceVdwA+fga=", "user"=>{"id"=>"629", "company_id"=>"1", "active"=>"1", "role_ids"=>["1", "3", "1"], "notification_ids"=>["1", "2", "3"]}, "company"=>"11", "id"=>"621"}
Below line checks the role_ids, if role_ids in params[:user] then take that one else take empty array :
means merge works like :
so you are getting role_ids like