Skip to content

Instantly share code, notes, and snippets.

@pokka
Created April 21, 2016 08:58
Show Gist options
  • Save pokka/b43439fc59c9143748156ab2d2143f0d to your computer and use it in GitHub Desktop.
Save pokka/b43439fc59c9143748156ab2d2143f0d to your computer and use it in GitHub Desktop.
Rails skip validates and callbacks, temporary
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