Class: Copyable::Saver

Inherits:
Object
  • Object
show all
Defined in:
lib/copyable/saver.rb

Class Method Summary collapse

Class Method Details

.save!(new_model, skip_validations) ⇒ Object

this is the algorithm for saving the new record



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/copyable/saver.rb', line 5

def self.save!(new_model, skip_validations)
  unless skip_validations
    ModelHooks.reenable!(new_model.class) # we must re-enable or validation does not work
    if !new_model.valid?(:create)
      ModelHooks.disable!(new_model.class)
      raise(ActiveRecord::RecordInvalid.new(new_model))
    else
      ModelHooks.disable!(new_model.class)
    end
  end
  new_model.save!
end