我有一个 ActiveRecord 类:
class Post < ActiveRecord::Base
has_many :posts_tags
has_many :tags, :through => :posts_tags
end
class Tag < ActiveRecord::Base
has_many :posts_tags
has_many :posts, :through => :posts_tags
end
class PostsTags < ActiveRecord::Base
belongs_to :posts
belongs_to :tags
end
当我想获得帖子标签时:
<% @posts = Post.all %>
<% @posts.each do |post| %>
<% if post.tags.count != 0 %>
<div class="post-tags">
<% post.tags.each do |tag| %>
<span><%= tag.name%></span>
<%end%>
</div>
<%end%>
<% end %>
我收到错误我该uninitialized constant Post::PostsTag
如何解决这个问题?