0
我有3个表格。 pin,流派和genres_pins。加入3个表格时出现未初始化的常量错误
genres_pins将pin和genre表连接到多对多。这里是我的设置:
插针型
class Pin < ActiveRecord::Base
belongs_to :user
belongs_to :type
has_many :replies
has_many :genres_pins
has_many :genres, :through => :genres_pins
end
类型型号
class Genre < ActiveRecord::Base
has_many :genres_pins
has_many :pins, :through => :genres_pins
end
GenresPins型号
class GenresPins < ActiveRecord::Base
belongs_to :pin
belongs_to :genre
end
查看
<% pin.genres_pins.each do |g| %>
<%= g.title %>
<% end %>
我得到以下错误:
uninitialized constant Pin::GenresPin
任何想法是怎么回事?我是Rails的新手,所以可能会错过一些显而易见的东西。
帮助表示赞赏。
非常感谢, Michael。
我只是做了这一点,并继续得到同样的错误。我的表名为genres_pins,我的模型文件名为genres_pins.rb。我是否也需要更改文件名? –
@MichaelGiovanniPumo文件名也应该改变。无需更改数据库表名 – arun15thmay
将它更改为genre_pin.rb时,仍然会出现相同的错误。奇怪的!所以,从复数到单数名称。 –