Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.2, nested resource, uninitialized constant
    primarykey
    data
    text
    <p>I'm having a problem with Rails 3.2.1, a nested resource keeps complaining about an uninitialized constant, I can't figure out why because to me it seems I've done the same as with a different model where this did work. At some point I thought I might be using a reserved word somewhere, but changing the model names didn't help...</p> <p><b>Error:</b></p> <pre><code>uninitialized constant Brand::Series Extracted source (around line #11): 8: &lt;/article&gt; 9: 10: 11: &lt;% @series.each do |serie| %&gt; 12: &lt;article class='serie_block'&gt; 13: &lt;%= serie.name %&gt; 14: &lt;/article&gt; </code></pre> <p><b>brand.rb</b></p> <pre><code>class Brand &lt; ActiveRecord::Base has_many :series, :order =&gt; "name, id ASC", :dependent =&gt; :destroy end </code></pre> <p><b>serie.rb</b></p> <pre><code>class Serie &lt; ActiveRecord::Base belongs_to :brand end </code></pre> <p><b>brands_controller.rb</b></p> <pre><code>def show @brand = Brand.find(params[:id]) @series = @brand.series end </code></pre> <p><b>brands/show.html.erb</b></p> <pre><code>&lt;% @series.each do |serie| %&gt; &lt;article class='serie_block'&gt; &lt;%= serie.name %&gt; &lt;/article&gt; &lt;% end %&gt; </code></pre> <p>I get the same "uninitialized constant Brand::Series" error when I try to create a new serie, but then it refers to "app/controllers/series_controller.rb:21:in `new'", which is this line "@serie = @brand.series.build".</p> <p><b>series_controller.rb</b></p> <pre><code># GET /Series/new # GET /Series/new.json def new @brand = Brand.find(params[:brand_id]) @serie = @brand.series.build respond_to do |format| format.html # new.html.erb format.json { render json: @serie } end end </code></pre> <p>Now the strange thing is that the relation seems to work, Rails is not complaining about "brands" not having a "series" method. But the actual creation of the series object seems to fail :s</p>
    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.
    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