Rails 3.2.1に問題があります。ネストされたリソースは初期化されていない定数について不平を言っています。これが機能した別のモデルと同じです。いくつかの時点で私は私が...どこかに予約語を使用しますが、モデル名は助けにはならなかった変えるかもしれないと思ったRails 3.2、ネストされたリソース、初期化されていない定数
エラー:
uninitialized constant Brand::Series
Extracted source (around line #11):
8: </article>
9:
10:
11: <% @series.each do |serie| %>
12: <article class='serie_block'>
13: <%= serie.name %>
14: </article>
brand.rb
class Brand < ActiveRecord::Base
has_many :series, :order => "name, id ASC", :dependent => :destroy
end
serie.rb
class Serie < ActiveRecord::Base
belongs_to :brand
end
brands_controller.rb
def show
@brand = Brand.find(params[:id])
@series = @brand.series
end
ブランド/ show.html.erb
<% @series.each do |serie| %>
<article class='serie_block'>
<%= serie.name %>
</article>
<% end %>
私が作成しようとすると、私は同じ "初期化されていない一定のブランド::シリーズ" のエラーが表示されますnew serieですが、 "app/controllers/series_controller.rb:21:` new '"という行です。この行は" @serie = @ brand.series.build "です。
series_controller.rb
# 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
は今、奇妙なことは、Railsは、「ブランド」、「シリーズ」の方法を持っていない文句を言っていない、関係が動作するように思われることです。しかし、実際のシリーズオブジェクトの作成は失敗しているようです。■
うわーありがとう!今、私の名前変更が間違っていた理由を理解しています:「シリーズ」の前に何かを追加しました(「product_series」のように...私は非母国語のスピーカーで、 「シリーズ」の実際は「シリーズ」です – Berggeit