I really don't know hot to set an extra attribute of a join model.

Possibly, for company and manager.

But the params you showed some time ago:

Parameters: {“utf8”=>“✓”,

“authenticity_token”=>" RpOtdQMIm6B45/e91h6ljXKpMCtRD//QJ+bP4knrcic=",

“manager”=>{“name”=>“q”, “surname”=>“”,

“fiscal_code”=>“1121111111111111”, “city”=>“”, “zip_code”=>“”,

“address”=>“”, “street_number”=>“”, “tel”=>“”, “email”=>“”},

“commit”=>“Crea Amministratore”, “company_id”=>“6”}

I did not see a

“role” => “Something”

in there.

Have you changed your view to now also have a “role” input field that is

returned upon submit?

Peter

That's because I didn't have @manager.managements.build in the controller.

I doubt it …

What you get back in “params” when the “create” action is called,

is a function of the code and view that is rendered by the “new” action.

Changing the code in the “create” action cannot change the params you receive when that “create” action is called.

Unless I totally misunderstood the way you would use “new” and “create” …

Anyway, does it work now, does that mean the params when entering the “create” action now do have the correct “role” key in them, than it is fine :slight_smile:

HTH,

Peter

Which is quite possible if Javascript is involved … I was only thinking of the simple classic case of

index => new => create => show

Peter

In the new action I didn't have @manager.managements.build so the form couldn't create the list of the roles to assign to management.role

Ah I see now, the code you refer to is in the “new” action as well (sorry, I did not check careful enough). And of course, there it can have that effect.

And sorry to the list for the large volume of posts about this case.

Peter

And sorry to the list for the large volume of posts about this case.

No no it's my ignorance, you have helped me a lot, I've solved a problem that I had for months. Really thanks a lot.

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">].

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.

I mean classification_id and not classification_type.