I am trying to send a POST request in my API (to create an user), but I always get all password validations erros because my password came to API as FILTERED.
I didn't understand this errors because if I create an User from the console and try to login at my API (JWT authentication with email and password) the password is also FILTERED but everything works fine.
I want to keep password filtered.
My user create method:
# POST /users
def create
@user = User.new(user_params)
if @user.save
render json: @user, status: :created, location: @user
else
render json: @user.errors, status: :unprocessable_entity
end
end
My file filter_parameter_logging.rb:
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
Curl command to create an User:
curl -H "Content-Type: application/json" -X POST -d '{"email":"caio@email.com","password":"123456","name":"Caio A","age":"18"}' http://localhost:3000/users
Request response:
{"password":["can't be blank","Password is required","Password minimum size is 4 characters"]}
With your curl command, you're not sending the params hash correctly.
curl -H "Content-Type: application/json" -X POST -d '{"user":
{"email":"caio@email.com","password":"123456","name":"Caio A","age":"18"}}' http://localhost:3000/users
or along those lines, according to your permitted strong params method def user_params