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]

1
  • 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.
    – kush
    Jan 6, 2009 at 19:17
-2

Try params["user_attributes"].

1
  • Nope sorry, didn't change anything.
    – kush
    Jan 5, 2009 at 22:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.