Method: ActiveRecord::Validations::ClassMethods#create!
- Defined in:
- lib/active_record/validations.rb
#create!(attributes = nil, &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.
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/active_record/validations.rb', line 1065 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 |