14

I need to skip the validation on create method.I am using Rails 4 and ruby 2

i have tried like this

@model.save(:validate => false)

it not working

1
  • How is @model.save(:validate => false) not working? What version of Rails are you using? Commented Sep 10, 2013 at 13:11

3 Answers 3

13

Assuming you are talking about ActiveRecord; In Rails 3 and 4 the way to skip validations and potentially persist invalid objects is as you describe:

@model.save(:validate => false)

In Rails 2 you'd need to do

@model.save(false)
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to do this using .create!() or .create()? (would just be a little more elegant in some use cases)
4

You can do this in model by

validates :some_attr, :presence => true, :on => :update

4 Comments

it should be validates not validate.... validate use for custom validation...though vote up
For that you can use some virtual attribute and set it while creating and doing validation in your model like this validates :some_attr, :presence => true, :if => Proc.new { virtual_attr.present? }
save(validate: false) also dosn't work, i am using activeldap
Yeah, the solution i have provided in my third comment will work for any source
1
validates :some_attr, :presence => true, :unless => :create

skips the validation JUST for create.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.