The params
hash is what you get when the user request the page. For example:
https://www.example.com/index.html?username=john&[email protected]
The params
hash would be
{username: 'john', email: '[email protected]'}
And you can assess then like params[:username]
.
Looks like you are trying to use strong parameters to set what the user can or cannot update. In that case, what you should do is
def update
user = User.find(params[:id])
user.update_attributes(params.require(:user).permit(:foo))
end
This will only allow the user to update the foo
attribute and nothing else.
Because this is so common, it is standard to write a private method called user_params
and just call that method when you call save
.
def update
user = User.find(params[:id])
user.update_attributes(user_params)
end
private
def user_params
params.require(:user).permit(:foo)
end