Reputation: 73
i've a problem with my app. I've two pair of models
the first:
class Nazione < ActiveRecord::Base
has_many :regiones
accepts_nested_attributes_for :regiones
attr_accessible :nome, :regiones_attributes
end
and
class Regione < ActiveRecord::Base
belongs_to :nazione
attr_accessible :nome, :nazione_id
end
and the second pair:
class Macrocategorie < ActiveRecord::Base
has_many :categories
accepts_nested_attributes_for :categories
attr_accessible :nome, :categories_attributes
end
and
class Categorie < ActiveRecord::Base
belongs_to :macrocategorie
attr_accessible :nome, :macrocategorie_id
end
they are used for the form in another model named Modulo1 :
class Modulo1 < ActiveRecord::Base
attr_accessible :nazione_organizzazione,:regione_organizzazione,:macrocat_sett_scient ,:cat_sett_scient
in the Modulo1's form when I use:
<%= f.label :Nazione%><br />
<%= f.collection_select :nazione_organizzazione, Nazione.order(:nome), :nome,
:nome,{:prompt => "Seleziona una Nazione"} %>
<%= f.label :Regione %><br>
<%= f.grouped_collection_select :regione_organizzazione, Nazione.order(:nome),
:regiones, :nome, :nome, :nome, {:prompt => "Seleziona una Regione"} %>
it works! but if I use
<%= f.label :Settore_Scientifico %><br>
<%= f.collection_select :macrocat_sett_scient, Macrocategorie.order(:nome), :nome,
:nome, {:prompt => "Seleziona una Macrocategoria"} %>
<%= f.grouped_collection_select :cat_sett_scient,
Macrocategorie.order(:nome),:categories,:nome, :nome,:nome,
{:prompt => "Seleziona una Categoria"} %>
it don't work!!! the errore is this:
uninitialized constant Macrocategorie::Category
Could anyone help me to solve this problem?
Upvotes: 0
Views: 42
Reputation: 5847
Rails fails to identify which class belongs on the other end of the association because your class names are not in English. You can set the class name explicitly:
class Macrocategorie < ActiveRecord::Base
has_many :categories, class_name: 'Categorie'
end
Another alternative is to define a new inflector in config/intializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'categorie', 'categories'
end
Upvotes: 0