Ruby on rails 选择类别:Rails 4多对多关联
对不起,我的英语不好 我在文章和类别之间创建了多对多关联 这是我的文章模型Ruby on rails 选择类别:Rails 4多对多关联,ruby-on-rails,ruby,associations,Ruby On Rails,Ruby,Associations,对不起,我的英语不好 我在文章和类别之间创建了多对多关联 这是我的文章模型 class Article < ActiveRecord::Base has_many :categorizations has_many :categories, through: :categorizations end 类文章 只需将true%>更改为true%>只需将true%>更改为true%>
class Article < ActiveRecord::Base
has_many :categorizations
has_many :categories, through: :categorizations
end
类文章
这是我的分类模型
class category < ActiveRecord::Base
has_many :categorizations
has_many :articles, through: :categorizations
end
类别
在本文中,我使用了分类模型
class Categorizations < ActiveRecord::Base
belongs_to :article
belongs_to :category
end
类分类
然后在种子文件中创建类别名称
但是我尝试在select中获取类别,但是我得到了这个错误
undefined method category_id' for <%= f.collection_select :category_id, Category.all, :id, :name, :include_blank => true %>
未定义的方法类别\u id'为true%>
只需将
true%>更改为true%>
只需将
true%>更改为true%>