jeudi 5 octobre 2017

uninitialized constant ruby model

I have 3 classes:
1. Article

class Article < ActiveRecord::Base
has_many :categories_articles
has_many :subcategories_articles
has_many :categories, :through => :categories_articles
has_many :subcategories, :through => :subcategories_articles
end

2.Category

class Category < ActiveRecord::Base
has_many :articles
has_many :categories_articles
has_many :categories_subcategories
has_many :subcategories, :through => :categories_subcategories
has_many :articles, :through => :categories_articles
end

3.The third class is the union of the first two, category_article

class CategoryArticle < ActiveRecord::Base
belongs_to :category
belongs_to :article
end

so, when i called in the view

<% f.collection_select(:category_ids, Category.all, :id, :name, {include_blank:"selects"},{class:'form-control select2 multi', :required=>true, multiple: true}) %>

i get this error

uninitialized constant Article::CategoriesArticle

The same goes for the class Subcategory and subcategory_article

Aucun commentaire:

Enregistrer un commentaire