Skip to content

With nested object collection in Update #2

@dinatih

Description

@dinatih

Hello,

That is my code:

I have a Company and a Position Models,
Company has many :positions and they have both a {Model}Translation Model.

When I create a Company and position in a multiple nested form:
<% form_for @Company do | company_form |%>
<% company_form.field_for :positions do | position_form |%>
<position_form.text_field :name>
<% end %>
<% end %>

Position#name is a translated attribute , all works, but when a i try to update the company and his position names the position name don't update.

And I got a "WARNING: Can't mass-assign these protected attributes: id"

Have you a idea of why that doesn't work please ?

P.S :
Started POST "/fr/companies/22" for 127.0.0.1 at Fri Jun 18 22:47:08 +0200 2010
Processing by CompaniesController#update as HTML
Parameters: {"company"=>{"name"=>"vzcxvx", "our_activity"=>"", "positions_attributes"=>{"0"=>{"name"=>"cx cxz cx ui", "id"=>"21"}}, "logo_url"=>"", "join_us"=>""}, "commit"=>"Confirmer les changements sur entreprise", "authenticity_token"=>"y1qgwSwWGOyef04agUnZrDr7OkYv6gBsW/yqvbt7S8k=", "id"=>"22", "locale"=>"fr"}
fr
_{"name"=>"vzcxvx", "our_activity"=>"", "logo_url"=>"", "positions_attributes"=>{"0"=>{"name"=>"cx cxz cx ui", "id"=>"21"}}, "join_us"=>""}_
Company Load (0.7ms) SELECT "companies".* FROM "companies" WHERE ("companies"."id" = 22) LIMIT 1
Position Load (0.3ms) SELECT "positions".* FROM "positions" WHERE ("positions".company_id = 22) AND ("positions"."id" IN (21))
CompanyTranslation Load (0.4ms) SELECT "company_translations".* FROM "company_translations" WHERE ("company_translations".company_id = 22) AND ("company_translations"."locale" = 'fr') ORDER BY created_at DESC LIMIT 1
WARNING: Can't mass-assign these protected attributes: id
CACHE (0.0ms) SELECT "companies".* FROM "companies" WHERE ("companies"."id" = 22) LIMIT 1
CompanyTranslation Load (0.2ms) SELECT "company_translations"."id" FROM "company_translations" WHERE ("company_translations"."locale" = 'fr') AND ("company_translations"."company_id" = 22) AND ("company_translations".id <> 23) LIMIT 1
Redirected to http://0.0.0.0:3000/fr/companies/22
Completed 302 Found in 624ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions