Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 选择类别:Rails 4多对多关联_Ruby On Rails_Ruby_Associations - Fatal编程技术网

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%>