How to bypass model validation

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

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|

:frowning:

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 => '<b style = "color:red">Password must be
alphanumeric</b>',
  :on => :create

-S