[Rails] How To Validate Boolean Form Field
Nithin Reddy
jashugan at gmail.com
Wed Mar 1 00:59:03 GMT 2006
On 2/28/06, Matthew Feadler <matthew at feadler.com> wrote:
> Hello all.
>
> I've got the following in my model:
>
> class Individual < ActiveRecord::Base
> validates_presence_of :first_name, :last_name, :street, :city,
> :state, :zip
> validates_acceptance_of :AZ_resident, :message => "You must be an
> Arizona resident."
> end
>
> The AZ_resident field is present and defined as boolean (PostgreSQL
> 8.1), but validation will not occur. I've tried adding :accept => "TRUE"
> and variations on the theme, to no avail.
>
> So, what am I doing wrong? How do I validate a boolean form field? It
> may be of use to know that my view is standard scaffold-generated stuff
> at the moment.
>
Have you tried this?
def validate
errors.add(:AZ_resident, "You must be an Arizona resident") if
AZ_resident = false
end
More information about the Rails
mailing list