I have a model named as user, this model have check of password between
length 6 to 16. But there are some scenarios where i cannot provide
password
while creating instance of user model. Here i am unable to save partial
entries in database because validation forbids me.
I want to know is there any to bypass validation checks in models
On Aug 21, 7:39 pm, “Arslan Ali” [email protected] wrote:
I have a model named as user, this model have check of password between
length 6 to 16. But there are some scenarios where i cannot provide password
while creating instance of user model. Here i am unable to save partial
entries in database because validation forbids me.
I want to know is there any to bypass validation checks in models
well if you pass false to save it won’t validate, or you can use
the :if/:unless options on the validations to control when they run.
Fred
Here’s how I’ve done it.
attr_accessor :step # to hold the step in the process
with_options :if => Proc.new{|record| record.step => 2} do |r|
r.validates_presence_of :credit_card, :ccv_code, :expiration_date
r.validates_numericality_of :credit_card
other validations
end
On Thu, Aug 21, 2008 at 1:40 PM, Frederick C. <
Arslan Ali wrote:
I have a model named as user, this model have check of password between
length 6 to 16. But there are some scenarios where i cannot provide
password
while creating instance of user model. Here i am unable to save partial
entries in database because validation forbids me.
I want to know is there any to bypass validation checks in models
I don’t know if you are using validates_format_of like I am but here is
an example of what I did:
validates_format_of :password, :with => /^\w+$/,
:message => ‘Password must be
alphanumeric’,
:on => :create
-S
and of course there’s a typo.
with_options :if => Proc.new{|record| record.step => 2} do |r|
should be
with_options :if => Proc.new{|record| record.step == 2} do |r|
