Forum: Ruby on Rails validates_acceptance_of, virtual attributes and mass assign

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E3eb0d7da7c54e7c8f247167bf886719?d=identicon&s=25 Matt (Guest)
on 2006-04-27 16:18
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.
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-04-27 18:13
(Received via mailing list)
On Apr 27, 2006, at 7:18 AM, Matt wrote:

> 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
This topic is locked and can not be replied to.