Answer the question
In order to leave comments, you need to log in
Do I misunderstand the purpose of param.require?
In the controller, you need to make sure that the parameters are present. If not, then in the API, the ActionController::ParameterMissing handler, as I understand it, must independently return a response about missing parameters.
I test like this:
ActionController::Parameters.new(foo1: 'bar1', foo2: 'bar2').require([:foo1, :foo2])
ActionController::ParameterMissing: param is missing or the value is empty: [:foo1, :foo2]
(render json: {status: "Error", message: "Missing parameter 'foo1'"}; return) unless param.has_key?(:foo1)
(render json: {status: "Error", message: "Missing parameter 'foo2'"}; return) unless param.has_key?(:foo2)
Answer the question
In order to leave comments, you need to log in
require
does not support arrays or multiple arguments. Call one by one.
params = ActionController::Parameters.new(foo1: 'bar1', foo2: 'bar2')
params.require(:foo1)
params.require(:foo2)
map
.
Maybe you mixed up require and permit?
apidock.com/rails/ActionController/Parameters/require
apidock.com/rails/ActionController/Parameters/permit
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question