dimanche 19 mars 2017

using attr_accessor for validation always returns an error

I'm trying to validate 2 fields which do no belong to the User table

attr_accessor :terms_of_service, :privacy_policy

 validates :terms_of_service, presence: true
 validates :privacy_policy, presence: true

in the request sent from the client, the :terms_of_service and :privacy_policy arguments can either be absent, or a boolean value.

Rails needs to pass validation only if the value is true (i.e send error only if parameter is absent or false)

however , for some reason - validation always fails regardless of the parameters being true or absent/false

I've even tried

 validates_presence_of :terms_of_service
 validates_presence_of :privacy_policy

and also

  validates :terms_of_service, acceptance: true
  validates :privacy_policy, acceptance: true

Aucun commentaire:

Enregistrer un commentaire