I am working on a existing app. One model has number of fields and they have set validations for many of them. I am trying create a object for testing purpose. I only need couple of fields. How do I skip the validation method and create an object?
class Article
validate :article_validation
#...rest of the model
end
All I want to do is do
Article.create(title: "sfsfsd")
in console.
And skip rest of the fields
a = Article.new(title: "sfsfsd")
a.save(validate: false)
Note that save also has the ability to skip validations if passed validate: false as an argument. This technique should be used with caution.
http://guides.rubyonrails.org/active_record_validations.html#skipping-validations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With