I am building a small marketplace app using rails and currently am stuck on trying to get my product edit and create pages to work. I have added image upload capability and have utilised simple forms to add details for the products but any time I try to proceed with editing I get the following error:
The action 'update' could not be found for ProductsController
Meanwhile if I try to create a new product I get a different error:
{"seller":["must exist"]}
Please see my code below:
-products_controller.rb
def create
@product = Product.create
@product_id = @product.id
if @product.save
render :show, status: :created
else
render json: @product.errors, status: :unprocessable_entity
end
end
end
# PATCH/PUT /products/1 or /products/1.json
def update
@product = Product.update (product_params)
if @product.save
render products:id, status: :created
else
render json: @product.errors, status: :unprocessable_entity
end
end
def product_params
params.require(:product).permit(:title, :description, :price, :buyer_id, :seller_id, :category, :image_url)
end
- edit.html.erb
<%= simple_form_for edit_product_path, url: {action: "update"} do |f| %>
<h1 class="heading">Edit Product</h1>
<%= render 'form', product: @product %>
<% end %>
-form.html.erb
<div class="form-inputs">
<%= f.input :title %>
<%= f.input :description %>
<%= f.input :price %>
<%= f.input :category, collection: ["footwear", "accessories", "menswear", "womenswear"] %>
<div class="form-group">
<% if product.picture.attached? %>
<%= image_tag product.picture, style: "width: 200px; display: block" %>
<% end %>
<%= f.file_field :picture %>
</div>
</div>
Any help I can get is greatly appreciated.