Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to update subcategory in Rails
    primarykey
    data
    text
    <p>I have Category and Products, Category has many product in it. I'm able to Edit Delete Create the Category, Also able to Create Delete Products in the Each Category, but want to Edit the each Product. I can access the single Product of particular Category by using link_to , and product controller is receiving the the product of particular Category. </p> <p>In html of Category where all Product belongs of that category has</p> <pre><code> &lt;%= link_to 'Edit', edit_category_product_path(product.category, product) %&gt; </code></pre> <p>Controller of Product, edit function is </p> <pre><code>@product = Product.where(params[:id]) </code></pre> <p>then my edit html is </p> <pre><code>&lt;%= form_for @product do |f| %&gt; &lt;% if @product.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@product.errors.count, "error") %&gt; prohibited this product from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @product.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :name %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :description %&gt;&lt;br /&gt; &lt;%= f.text_area :description %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :price %&gt;&lt;br /&gt; &lt;%= f.text_field :price %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;%= link_to 'Back', category_products_path %&gt; </code></pre> <p>I'm getting this error when try to Edit the product</p> <pre><code>NoMethodError in Products#edit Showing C:/Sites/propoolpro6/app/views/products/edit.html.erb where line #3 raised: undefined method `model_name' for ActiveRecord::Relation:Class Extracted source (around line #3): 1: &lt;h1&gt;Editing product&lt;/h1&gt; 2: 3: &lt;%= form_for @product do |f| %&gt; 4: &lt;% if @product.errors.any? %&gt; 5: &lt;div id="error_explanation"&gt; 6: &lt;h2&gt;&lt;%= pluralize(@product.errors.count, "error") %&gt; prohibited this product from being saved:&lt;/h2&gt; Rails.root: C:/Sites/propoolpro6 Application Trace | Framework Trace | Full Trace app/views/products/edit.html.erb:3:in `_app_views_products_edit_html_erb___584392485_32651052' Request Parameters: {"category_id"=&gt;"1", "id"=&gt;"3"} </code></pre> <p><strong>Note:</strong> i have used this 2, but same error, </p> <pre><code>&lt;%= form_for(@product) do |f| %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload