Rails n00b here ...如何渲染HABTM关联?
我在帖子和类别模型之间有* has_and_belongs_to_many *关联。我想呈现的类别为每个岗位,像这样:
<%= post.Categories.each do |category| %>
<div id="categories_home">
<ul>
<li><%= category.description %></li>
</ul>
</div>
我得到一个错误;我一直无法找到一个例子来说明如何正确呈现这些类型的关系。
我应该使用has_and_belongs_to_many:through关联来实现一个响应动作来获取CategoriesPosts表的所有记录,然后使用post_id遍历表。
在此先感谢!
如果问题仍然存在,请在您的帖子中包含模型以及错误消息,并确保您运行了迁移 – 2012-03-25 09:13:33