Note that there are some explanatory texts on larger screens.

plurals
  1. PONoMethodError in Characters#new
    primarykey
    data
    text
    <p>I am new to Rails.I am creating a Rails project in which Product and Character are the models.I have the following Questions.</p> <p>Q1. Is the given association between the two models is right?</p> <pre><code>class Product &lt; ActiveRecord::Base has_many :characters end class Character &lt; ActiveRecord::Base belongs_to :product end </code></pre> <p>Q2. I created a link to add new character in the 'show' page of the products such if we click add new character it should display a 'new' page of characters in which i should have a dropdown list of character names(i.e., height,width,weight and color) but it is not.</p> <p>It is showing <code>NoMethodError in Characters#new</code> error.</p> <p>Error raised in the below line of my characters/new file.</p> <pre><code> collection_select(:product, :c_id, @character, :id, :name) </code></pre> <p>Note: I had created the values for name attribute as height,weight,width,color in the characters before migrating it.</p> <p>Q3. If that works(i.e., Q2), i want to show the character name and value in the 'show page of products.For this how can i redirect to 'show' page of products..?</p> <p>My characterscontroller for new,show and create:</p> <pre><code>def show @product = Product.find(params[:id]) @character = Character.find(params[:id]) end def new @character = Character.new(params[:character]) @product = Product.find(params[:id]) end def create @character = Character.new(params[:character]) if @character.save redirect_to :action =&gt; 'show', :id =&gt; @product.id else render :action =&gt; 'new' end end </code></pre> <p>Well now, after entering the values for the character in the characters/new and clicking create button it is trowing the following error</p> <pre><code>ActiveRecord::RecordNotFound in ProductsController#show Couldn't find Product without an ID </code></pre> <p>I want to show the character name and value in the products/show. the above error is stopping me to do that..</p> <p>My show method in productscontroller:</p> <pre><code>def show @product = Product.find(params[:id]) @character = Character.find(:all) end </code></pre>
    singulars
    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.
 

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