A
A
Anatoly Chernyshev2019-05-30 17:02:34
Ruby on Rails
Anatoly Chernyshev, 2019-05-30 17:02:34

Unpermitted parameter: :user?

I send a request to the server

curl -X POST \
  http://localhost:3000/user \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "[email protected]",
  "password": "123456",
  "password_confirmation": "123456"
}'

In the controller I have
def user_params
    params.permit(
      :email, :password, :password_confirmation
    )
  end

The model itself
class User < ApplicationRecord
  has_secure_password
  validates :email, presence: true, uniqueness: true
  validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }
  validates :password,
            length: {minimum:6},
            if: -> { new_record? || !password.nil? }
end

But in the logs I see the following situation
Processing by UserController#create as */*
  Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "user"=>{"email"=>"[email protected]"}}
Unpermitted parameter: :user

Where can this user parameter come from if I don't pass it directly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Alekseiev, 2019-05-30
@kayn23

This is how permitted_params are passed
Here you can read

M
Mcalexvrn, 2019-06-04
@Mcalexvrn

Hey! Look in config/initializers/wrap_parameters.rb file
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [] # empty array to disable parameter wrapping.
end
read here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question