Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With nested object collection in Update #2

Open
dinatih opened this issue Jun 19, 2010 · 3 comments
Open

With nested object collection in Update #2

dinatih opened this issue Jun 19, 2010 · 3 comments

Comments

@dinatih
Copy link

dinatih commented Jun 19, 2010

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

@marcusg
Copy link

marcusg commented Sep 7, 2010

i have the same problems using nested attributes but i don't get the mass-assign warning. the translation table gets no update. any ideas?

@dinatih
Copy link
Author

dinatih commented Feb 2, 2011

This works if we change a non translated attribute at the same time of the translated attributes. So I think this is due to update_attribute method which not update attribute if no non-translated attributes has changed

@wolfgangihloff
Copy link

I see the same happening for me as well. I get the warning, data is written though. I use form_for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants