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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs