Hi everyone, I''m having trouble validating a model. The corresponding table has some boolean columns: create_table :permissions do |t| t.column :project_id, :integer, :null => false t.column :group_id, :integer, :null => false t.column :read, :boolean, :null => false, :default => false t.column :write, :boolean, :null => false, :default => false t.column :admin, :boolean, :null => false, :default => false end In the mode I validate with the following : validates_presence_of :boolean_field The problem is that if I set the :boolean_field to false, the validation fails. I absolutely need to set the boolean field to ''true'' for the validation to pass. This isn''t normal, as true AND false are both valid values for a boolean field. Anyone else aware of this problem? Any workarounds? Thanks, Jd
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jean-Daniel Beaubien wrote:> Hi everyone, > > I''m having trouble validating a model. The corresponding table has some > boolean columns: > create_table :permissions do |t| > t.column :project_id, :integer, :null => false > t.column :group_id, :integer, :null => false > t.column :read, :boolean, :null => false, :default => false > t.column :write, :boolean, :null => false, :default => false > t.column :admin, :boolean, :null => false, :default => false > end > > In the mode I validate with the following : validates_presence_of > :boolean_field > > The problem is that if I set the :boolean_field to false, the validation > fails. I absolutely need to set the boolean field to ''true'' for the > validation to pass. This isn''t normal, as true AND false are both valid > values for a boolean field. > > Anyone else aware of this problem? Any workarounds?Why do you need to validate the presence of the boolean? Your schema states that it will default to false, so unless you explicitly give someone permission to read/write/admin then they won''t have the permission. I don''t think you need to validate the presence of the boolean fields. Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE5ycoMyx0fW1d8G0RAjZKAJ99+dOKlFqhdUTF+gyWn1APN1f41wCfZfC6 8e1TU6bmIIN3oWr4kWnmvXs=WhYV -----END PGP SIGNATURE-----
On 19-aug-2006, at 16:58, zdennis wrote:> Why do you need to validate the presence of the boolean?Because it might be nil. -- Julian ''Julik'' Tarkhanov please send all personal mail to me at julik.nl
In your migration you state that the boolean field is not null-able, therefore its only possible values are True and False. What type of errors are you hoping to catch with your validates_presence_of? On 8/19/06, zdennis <zdennis@mktec.com> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Jean-Daniel Beaubien wrote: > > Hi everyone, > > > > I''m having trouble validating a model. The corresponding table has some > > boolean columns: > > create_table :permissions do |t| > > t.column :project_id, :integer, :null => false > > t.column :group_id, :integer, :null => false > > t.column :read, :boolean, :null => false, :default => false > > t.column :write, :boolean, :null => false, :default => false > > t.column :admin, :boolean, :null => false, :default => false > > end > > > > In the mode I validate with the following : validates_presence_of > > :boolean_field > > > > The problem is that if I set the :boolean_field to false, the validation > > fails. I absolutely need to set the boolean field to ''true'' for the > > validation to pass. This isn''t normal, as true AND false are both valid > > values for a boolean field. > > > > Anyone else aware of this problem? Any workarounds? > > Why do you need to validate the presence of the boolean? Your schema states that it will default to false, so unless you > explicitly give someone permission to read/write/admin then they won''t have the permission. I don''t think you need to validate the > presence of the boolean fields. > > Zach > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2.2 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQFE5ycoMyx0fW1d8G0RAjZKAJ99+dOKlFqhdUTF+gyWn1APN1f41wCfZfC6 > 8e1TU6bmIIN3oWr4kWnmvXs> =WhYV > -----END PGP SIGNATURE----- > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >