I have ParameterMissing error for the update method. I used patch to trigger this method, here is the command
curl -i -X PATCH 'localhost:3000/products/1' -d '{"product":{ "title": "t", "price": "1.23", "count": "3"}}'
Product_controller.rb
def edit
@product = Product.find(params[:id])
end
def update
# use update method
@product = Product.find(params[:id])
# use update_attributes to update the record
if @product.update_attributes(product_params)
render json: { status: :ok, message: 'Product updated ', data: @product }
else
render json: { status: :error, message: 'Product not available', data: @product }
end
end
private
def product_params
params.require(:product).permit(:title, :price, :count)
end
curl -i -X PATCH 'localhost:3000/products/1' -d '{"product":{ "title": "t", "price": "1.23", "count": "3"}}' -H 'Content-Type: application/json'
I think the problem is data is JSON content, then, you should use header:
Content-Type: application.json