I have an rails app with json api. So far I can create single objects via POST request.
It's fairly simple:
def create
customer = Customer.new(customer_params)
if customer.save
render json: customer, status: 201
else
render json: customer.errors, status: 422
end
end
and:
private
def customer_params
params.require(:customer).permit(:name, :city)
end
Now I want to create multiple customers by passing an array in my http request. Like this:
{
"customer": [
{
"name": "foo",
"city": "New York"
},
{
"name": "bar",
"city": "Chicago"
}
]
}
However, I don't know how to approach this. The first issue is that my strong parameters function doesn't accept arrays. Is there a way to use strong parameters and let me loop through the array?