Rails: for every array giving error?

In one form, I create a territory and edit multiple users. Below are "user_attributes" for users and "name" for territory. So for each user_attribute, I wanted to update the user model.

PARAMS

{ "territory"=>{"name"=>"Central Canada",
  "user_attributes"=>[{"user_id"=>"30"},{"user_id"=>"30"}]}
}

      

create action

@territory = @current_account.territories.new[:territory]
params[:user_attributes].each do |item|
  @user = User.find(item[:user_id])
  @user.update_attribute(:territory_id, @territory.id)
end 

      

But the rails throw back that the [: user_attributes] parameters are zero. But you can see from the parameters it is not there. Did I miss something?

+1


source to share


2 answers


From what you posted, the hash user_attributes

is inside your hash territory

. That should be your problem - either move it outside or doparams[:territory][:user_attributes]



+6


source


Try the ["user_attributes"] options.



-2


source







All Articles