Alder Green
2006-Jun-24 16:28 UTC
[Rails] Mass assignment to an AR that would call assignment methods.
Hi I have an AR instance foo that recently got an assignment method #bar=. Before this addition I could use mass-assignment for foo with: Foo.new(params[:foo]) and: foo.attributes = params[:foo] But appearantly assignment methods like #bar= don''t get called with the 2 examples above. I have to: foo = Foo.new params[:foo].each do |key, val| rec[key] = val end and something very similar for updating. Is this the best way, or is there some convenient builtin mass-assignment method which does call the appropriate assigment method for each attribute? -- -Alder
Maybe Matching Threads
- cancan breaks scoped mass assignment
- ActionView::Helpers::FormHelper instance methods should take an object reference rather than an object_name.
- WARNING: Can't mass-assign these protected attributes: active
- How to SELECT from multiple talbes with AR#find and associations?
- validates_acceptance_of, virtual attributes and mass assign