0

I am facing a problem using form_for in rails. I am developing an online shopping application. I have a resource category and category has many products. I want to edit a product's details.

First of all edit page is not filling up the product's details in the form

Secondly, On saving the edits browser is throwing following error.

No route matches [POST] "/categories/3/products/1/edit"

Here is my edit view code -

<h1>Edit Product</h1>

<%= form_for category_product_path(@product.category.id, @product.id) do |f| %>

 <table align="center" border="1" cellpadding="10">
  <tr>
    <td>Name</td>
    <td><%= f.text_field :name %></td>
  </tr>
  <tr>
    <td>Price</td>
    <td><%= f.text_field :price %></td>
  </tr>
  <tr>
    <td>Description</td>
    <td><%= f.text_field :description %></td>
  </tr>

</table>


  <p>
    <%= f.submit %>
  </p>

<% end %>

I want to know how form_for works and how to write routes in form_for

Shunan
  • 3,165
  • 6
  • 28
  • 48

0 Answers0