I have an array of objects which i'm sending to the controller
through ajax
.
My ajax request is like this:
$.ajax({
data: {
product: [{'name': 'ahmad', 'price': 'tench', 'quantity': '12'}, {'name': 'gulshan', 'price': 'tench', 'quantity': '12'}]
},
url: '',
type: "POST",
dataType: "json",
success: function ( data ) {
console.log(data);
// this.setState({ comments: data });
}.bind(this)
});
Controller:
def create
@product = Product.new(product_params)
if @product.save
render json: @product
else
render json: @product.errors, status: :unprocessable_entity
end
end
private
def product_params
params.fetch(:product).permit!
end
But if i use create
method then also i'm getting the same error.
I'm attaching a screenshot of the parameters in the rails log.
I dont understand why i'm getting this error?
Please help.