Я хотел бы обновить count: = count-1 для продукта. Я использовал редактирование вместо обновления, потому что я хотел бы пропустить форму. Я также перечислил маршрут, сгенерированный системой.
Вот ошибка: «ActionController :: ParameterMissing в ProductsController # edit»
Product_controller.rb
def edit
@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
edit.html.erb
<%= form_with(model: @product, local: true) do |form| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@product.errors.count, "error") %> prohibited
this product from being saved:
</h2>
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= form.label :title %><br>
<%= form.text_field :title %>
</p>
<p>
<%= form.label :price %><br>
<%= form.text_field :price %>
</p>
<p>
<%= form.label :count %><br>
<%= form.text_field :count %>
</p>
<p>
<%= form.submit %>
</p>
<% end %>
Маршруты:
welcome_index_path GET /welcome/index(.:format) welcome#index
products_path GET /products(.:format) products#index
POST /products(.:format) products#create
new_product_path GET /products/new(.:format) products#new
edit_product_path GET /products/:id/edit(.:format) products#edit
product_path GET /products/:id(.:format) products#show
PATCH /products/:id(.:format) products#update
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy