Hello,
I am trying to authenticate using has_secure_password, but when I send a payload as shown below, I cannot access the password field.
{
"email": "foo@example.com",
"name": "Chazy Ches",
"password": "secureP@ssword",
"phone_number": "+1234567890"
}
My parameter configuration is as follows
def user_params
params.require(:user).permit(:name, :email, :password, :phone_number)
end
The parameters handled in the “user” object in the Rails log appear like this.
Processing by UsersController#create as JSON
Parameters: {"email"=>"foo@example.com", "name"=>"Chazy Ches", "password"=>"[FILTERED]", "phone_number"=>"+1234567890", "user"=>{"name"=>"Chazy Ches", "email"=>"foo@example.com", "phone_number"=>"+1234567890"}}
As you can see, there is no “password” in the “user” object. And I get a validation error because ‘password’ is not returned from the user params method.
{
"user": {
"email": "foo@example.com",
"name": "Chazy Ches",
"password": "secureP@ssword",
"phone_number": "+1234567890"
}
}
It works this way, but I do not want to send the payload inside the user object.
How can I solve this problem? Thanks.