Difference Between Save(False) and Save(: Validate => False)

Difference Between Save(False) and Save(: Validate => False)

What's the difference between save(false) and save(:validate => false)? From what I can tell, the functionality is the same. The version that uses :validate is in the api which leads me to believe save(false) is a deprecated version? This came up for me when following this: . The guide has save(false) in there but I was getting errors when using it. I switched it to the :validate version and that worked fine.

2 Answers

In Rails versions before than 3, save was a method in ActiveRecord::Base and you could pass false to it in order to bypass validations.

In Rails 3, save was moved to ActiveRecord::Persistance and since then you should pass :validate => false to save in order to bypass validations.

1

All the validation from model are skipped when we use validate: false

@user = User.new(....)

@user.save(validate: false)

Action base disable validation

Skip Field validation

Example

class User < ActiveRecord::Base

validates_presence_of :password, :on => :update

end

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.