Created
April 21, 2016 08:58
-
-
Save pokka/b43439fc59c9143748156ab2d2143f0d to your computer and use it in GitHub Desktop.
Rails skip validates and callbacks, temporary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord::Persistence::ClassMethods | |
def create!(attributes = nil, &block) | |
if attributes.is_a?(Array) | |
attributes.collect { |attr| create!(attr, &block) } | |
else | |
object = new(attributes, &block) | |
[:save,:create].each { |cb| object.class.reset_callbacks cb } | |
object.save(validate: false) | |
object | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment