在视图中连接3个表时未初始化的常量错误

时间:2014-01-20 12:18:38

标签: ruby-on-rails ruby-on-rails-4

我有3张桌子。 pin,genre和genres_pins。

genres_pins将pin和genre表连接在一起以及多对多。这是我的设置:

Pin Model

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的新手,所以可能会遗漏一些愚蠢的东西。

帮助表示赞赏。

非常感谢, 迈克尔。

1 个答案:

答案 0 :(得分:2)

class GenrePin < ActiveRecord::Base
   belongs_to :pin
   belongs_to :genre
end

应更改班级名称

相关问题