1

In one form I am creating a territory and editing multiple users. The "user_attributes" below are for the users and the "name" is for the 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 rails is kicking back that params[:user_attributes] is nil. But you can see from the params its not. Am I missing something??

2 Answers 2

6

From what you posted, your user_attributes hash is INSIDE your territory hash. That should be your problem -- either move it outside, or do params[:territory][:user_attributes]

Sign up to request clarification or add additional context in comments.

1 Comment

That was it, it worked. I had originally tried that but it didn't work. It turned out that the @user.update_attribute line wasn't working because @territory wasn't saved yet so it wasn't assigned an ID yet.
-2

Try params["user_attributes"].

1 Comment

Nope sorry, didn't change anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.