Я могу получить запись из запроса GET, но не могу обновить запись с помощью запроса PATCH.Любое предложение о том, как отладить эту проблему?
def show
@product = Product.find(params[:id])
render json: { status: :ok, message: 'Find the product ', data: @product }
end
def update
@product = Product.find(params[:id])
if @product.update(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:
curl -i -X GET 'localhost:3000/products/1'
{"status":"ok","message":"Find the product ","data":{"id":1,"title":"cell phone","price":"999","count":"99","created_at":"2019-01-19T16:12:09.717Z","updated_at":"2019-01-21T09:01:56.056Z"}}
curl -i -X PATCH 'localhost:3000/products/1' -d '{"product":{ "title": "t", "price": "1.23", "count": "3"}}'
{"status":"error","message":"Product not available!!!","data":{"id":1,"title":"t","price":"1.23","count":"3","created_at":"2019-01-19T16:12:09.717Z","updated_at":"2019-01-21T09:01:56.056Z"}}
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
product_purchase GET /products/:product_id/purchase(.:format) products#purchase
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PATCH /products/:id(.:format) products#update
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
root GET /