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

3
  • Update the question with the routes Commented Jul 20, 2017 at 6:31
  • 2
    BTW try changing your form_for to <%= form_for [@product.category, @product] do |f| %> Commented Jul 20, 2017 at 6:33
  • rake routes detail update please Commented Jul 20, 2017 at 6:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.