On 10 January 2012 12:15, Peter Vandenabeele <pe...@vandenabeele.com> wrote:
> On Tue, Jan 10, 2012 at 11:33 AM, Mauro <mrsan...@gmail.com> wrote:
>>
>> I have:
>>
>> class Company < ActiveRecord::Base
>>  has_many :categorizations
>>  has_many :categories, :through => :categorizations
>>  has_many :managements
>>  has_many :managers, :through => :managements
>>  has_many :tenders
>>  has_many :documents, :dependent => :destroy
>>
>>  accepts_nested_attributes_for :managers
>>  accepts_nested_attributes_for :documents
>>  accepts_nested_attributes_for :categorizations
>>
>> then the form is:
>>
>> = semantic_form_for @company do |f|
>>  = f.input :name
>> = f.semantic_fields_for :manager do |manager|
>>  = manager.inputs :name, :fiscal_code, :city, :zip_code, :address,
>> :street_number, :tel, :email
>>
>> when I submit the form raise the error:
>>
>> unknown attribute: manager
>>
>>
>> {"utf8"=>"✓",
>>  "authenticity_token"=>"V5GsRKLK8cRrGuUh2Jv4DB9wSYWG8ASCxHkd0Ur3o8s=",
>>  "company"=>{"manager"=>{"name"=>"",
>>  "fiscal_code"=>"",
>>  "city"=>"",
>>  "zip_code"=>"",
>>  "address"=>"",
>>  "street_number"=>"",
>>  "tel"=>"",
>>  "email"=>""}},
>>  "commit"=>"Create Company"}
>>
>> I think there is nothing wrong but perhaps I miss something.
>
>
> If I am not mistaken,  accepts_nested_attributes_for :managers
> adds a setter method of the style  company.managers_attributes=
>
> I think your hash that is coming in from the Submit tries to do
> company.manager= {"name"
>>
>> =>"",
>>  "fiscal_code"=>"",
>>  "city"=>"",
>>  "zip_code"=>"",
>>  "address"=>"",
>>  "street_number"=>"",
>>  "tel"=>"",
>>  "email"=>""}
>
>
> and Rails complains that 'manager' is not an attribute of company
> (really saying that the Company#manager= methods is not defined).
>
> To validate this hypothesis, try something like, e.g. in rails console
>
>> Company.new.methods.grep(/manager/)
>
> and check which exact methods are available for 'manager*' on the Company
> class.
> I would expect you see there:
>
> [... :managers_attributes=, ...]


Here is the grep result:

[:before_remove_for_managers=, :after_remove_for_managers,
:after_add_for_managers?, :autosave_associated_records_for_managers,
:manager_ids=, :after_remove_for_managers?,
:validate_associated_records_for_managers,
:before_remove_for_managers?, :before_add_for_managers,
:after_add_for_managers=, :before_add_for_managers?, :managers,
:before_add_for_managers=, :after_remove_for_managers=,
:after_add_for_managers, :managers=, :before_remove_for_managers,
:manager_ids]

there is a method managers so I changed

manager.semantic_fields_for :manager
to
manager.semantic_fields_for :managers

and in the controller

@company.managers.build

now it seems to work.
Thank you.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to