2012-08-27 46 views
0

我正在使用http://www.youtube.com/watch?v=PUHmX18Zmyk视频制作博客。 我的帖子模型无法关联类别和帖子

class Post < ActiveRecord::Base 
    attr_accessible :body, :publish_date, :title, :user_id 
    validates_presence_of :title, :body, :publish_date, :user_id 
    belongs_to :user 
    has_and_belongs_to_many :categories 
end 

分类模型是

class Category < ActiveRecord::Base 
    attr_accessible :name 
    validates_presence_of :name 
    has_and_belongs_to_many :posts 
end 

在视频,他用这样的代码来生成新的岗位

<% f.association :categories, :as => :checkboxes %> 

类别的清单,但我有错误

undefined method `association' for #<ActionView::Helpers::FormBuilder:0xb5e82b40> 

什么是使类别列表的正确方法?

+1

您使用的是simple_form gem吗?如果没有,则在表单构建器中不提供'f.association'方法。如果是,请检查以确保您不仅调用'form_for'而且调用'simple_form_for' –

回答

相关问题