I have a basic API built by rails new my_api --api
, then rails g scaffold model name age
.
I would like to alter the model_params
method to accept a JSON array. How can I do this?
The current method is the default:
def model_params
params.require(:model).permit(:name, :age)
end
What I've tried
I have tried this:
def model_params
params.require(:model).permit?([:name, :age])
end
But I get
Completed 400 Bad Request in 10ms (ActiveRecord: 10.3ms)
ActionController::ParameterMissing (param is missing or the value is empty: model):
app/controllers/models_controller.rb:83:in `model_params'
app/controllers/models_controller.rb:29:in `create'
Note
The curl request I make is
curl -H "Accept: application/json" -H "Content-type: application/json" -d '[{"name": "Fred", "age": "5"}, {"name": "Fred", "age": "5"}, {"name": "Fred", "age": "5"}]' "http://localhost:3000/models"