Method: ActiveRecord::Validations::ClassMethods#create!
- Defined in:
- lib/active_record/validations.rb
#create!(attributes = nil, options = {}, &block) ⇒ Object
Creates an object just like Base.create but calls save! instead of save so an exception is raised if the record is invalid.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_record/validations.rb', line 35 def create!(attributes = nil, = {}, &block) if attributes.is_a?(Array) attributes.collect { |attr| create!(attr, , &block) } else object = new(attributes, ) yield(object) if block_given? object.save! object end end |