Reputation: 919
Sorry for my English
I have a create many to many association between articles and categories
this is my article model
class Article < ActiveRecord::Base
has_many :categorizations
has_many :categories, through: :categorizations
end
this is my category model
class category < ActiveRecord::Base
has_many :categorizations
has_many :articles, through: :categorizations
end
in this my categorization model
class Categorizations < ActiveRecord::Base
belongs_to :article
belongs_to :category
end
then I have create the categories names in the Seed file
but I try to get the categories in a select but I get this Error
undefined method category_id' for <%= f.collection_select :category_id, Category.all, :id, :name, :include_blank => true %>
Upvotes: 1
Views: 1435
Reputation:
Just change <%= f.collection_select :category_id, Category.all, :id, :name, :include_blank =>
true %> to <%= f.collection_select :category_ids, Category.all, :id, :name, :include_blank => true %>
Upvotes: 4