Answer the question
In order to leave comments, you need to log in
How to return 'Unpermitted parameter' error when validating fields in REST API?
There is code like this:
def safe_params(params)
params.require(:survey).permit(:name, :question)
end
def update
if @survey.update(safe_params(params))
render json: { status: "Success" }
else
render json: { status: "Error", message: 'Validation errors', errors: @survey.errors }
end
end
safe_params
in @survey.errors this type of error is handled?
Answer the question
In order to leave comments, you need to log in
Can be defined in a file config/environments/development.rb
for the entire project:
You also need to decide how to proceed for production in the config/environments/production.rb
.
If this behavior is only needed for the API controller, then
class ApiController < ApplicationController
# <<<< добавить
# Always raise errors on unpermitted parameters
ActionController::Parameters.action_on_unpermitted_parameters = :raise
# <<<<
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question