Richard Sandilands
2006-Jun-12 04:16 UTC
[Rails] Validating a non-object attribute in a form via checkbox?
Hi there A user can place an ad with various attributes via a form; however, I want the user to check a box signifying that they''ve read the terms and conditions for use of the site. So the ''terms'' is not an attribute of the Advertisement model. I could check that the user has ticked the box in my controller but would like to bundle this up with the validation process. How to ensure that the checkbox is ticked before the ad object is saved as part of the model validation? Any clues appreciated Richard Sandilands
Chris T
2006-Jun-12 07:19 UTC
[Rails] Validating a non-object attribute in a form via checkbox?
Should the terms perhaps be part of the user model -- it could then be part of the user validation (using *validates_acceptance_of)*? Richard Sandilands wrote:> Hi there > > A user can place an ad with various attributes via a form; however, I > want the user to check a box signifying that they''ve read the terms > and conditions for use of the site. > > So the ''terms'' is not an attribute of the Advertisement model. I > could check that the user has ticked the box in my controller but > would like to bundle this up with the validation process. > > How to ensure that the checkbox is ticked before the ad object is > saved as part of the model validation? > > Any clues appreciated > > Richard Sandilands > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Richard Sandilands
2006-Jun-13 23:05 UTC
[Rails] Re: Validating a non-object attribute in a form via checkbox?
Ah, validates_acceptance_of !! That works fine and is exactly what I was after. many thanks Richard On 6/12/06, Chris T <ctmailinglists@googlemail.com> wrote:> Should the terms perhaps be part of the user model -- it could then be > part of the user validation (using *validates_acceptance_of)*? > > Richard Sandilands wrote: > > Hi there > > > > A user can place an ad with various attributes via a form; however, I > > want the user to check a box signifying that they''ve read the terms > > and conditions for use of the site. > > > > So the ''terms'' is not an attribute of the Advertisement model. I > > could check that the user has ticked the box in my controller but > > would like to bundle this up with the validation process. > > > > How to ensure that the checkbox is ticked before the ad object is > > saved as part of the model validation? > > > > Any clues appreciated > > > > Richard Sandilands > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Seemingly Similar Threads
- assert_difference gives undefined method error in unit tests
- Data relationships for e-commerce: users, orders, addresses
- Credit card processing through Australian gateways (eway etc)
- validates_acceptance_of + functional testing
- Shovel/TextDrive error: missing SSHAgent.socket