Matt
2006-Apr-27 14:22 UTC
[Rails] validates_acceptance_of, virtual attributes and mass assign
Hi, I''ve a question concerning validates_acceptance_of method. Documentation says that the validated attribute is a virtual one, without a field in db. But when I add such an attribute to my form (say check_box(:xyz, :agreement)), it''s passed in params[:xyz][:agreement], but not assigned when calling Xyz.new(params[:xyz]), probably because corresponding field doesn''t exist in db. I''ve to manually assign it afterwards. This is not very convenient, since I''ve to do it in every action that''s creating Xyz objects. Is there a way to mass assign all attributes, not only those that have columns in db? Thanks, Matt. -- Posted via http://www.ruby-forum.com/.
Tom Mornini
2006-Apr-27 16:12 UTC
[Rails] validates_acceptance_of, virtual attributes and mass assign
On Apr 27, 2006, at 7:18 AM, Matt wrote:> I''ve a question concerning validates_acceptance_of method. > > Documentation says that the validated attribute is a virtual one, > without a field in db. But when I add such an attribute to my form > (say > check_box(:xyz, :agreement)), it''s passed in params[:xyz][:agreement], > but not assigned when calling Xyz.new(params[:xyz]), probably because > corresponding field doesn''t exist in db. I''ve to manually assign it > afterwards. > > This is not very convenient, since I''ve to do it in every action > that''s > creating Xyz objects. Is there a way to mass assign all attributes, > not > only those that have columns in db?In the model, use: attr_accessible :fieldname_confirmation -- -- Tom Mornini