Can I ask some help for another similar problem?
The first problem we have solved with your great help was:
class Company < ActiveRecord::Base
has_many :managements
has_many :managers, :through => :managements
class Manager < ActiveRecord::Base
has_many :managements
has_many :companies, :through => :managements
Management has an extra attribute :role and to assign a value to role
when we create a new company.manager we have set in the manager
controller:
def create
@company = Company.find(params[:company_id])
@manager = Manager.new(params[:manager])
@manager.managements.build(:role => params[:manager][:role],
:company => @company)
.....
It works!!.
Now I've extended Company model and it is.
class Company < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
has_many :managements
has_many :managers, :through => :managements
class Category < ActiveRecord::Base
has_many :categorizations
has_many :companies, :through => :categorizations
Categorization has two extra attributes, :classification_id and :amount.
Now I want to assign a value to classification_type when I create a new company.
In the controller I've done:
def create
@company = Company.new(params[:company])
@company.categorizations.build(:classification_id =>
params[:company][:classification])
but it creates two categorizations:
[#<Categorization id: 111, company_id: 106, category_id: nil,
classification_id: 2, amount: nil, created_at: "2012-01-16 20:12:18",
updated_at: "2012-01-16 20:12:18">, #<Categorization id: 112,
company_id: 106, category_id: 1, classification_id: nil, amount: nil,
created_at: "2012-01-16 20:12:18", updated_at: "2012-01-16
20:12:18">].