Module: ActiveRecord::Extensions::CreateAndUpdate::ClassMethods
- Defined in:
- lib/ar-extensions/create_and_update.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#create_with_extension(attributes = nil, options = {}, &block) ⇒ Object
Creates an object, instantly saves it as a record (if the validation permits it), and returns it.
-
#create_with_extension!(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.
Instance Method Details
#create_with_extension(attributes = nil, options = {}, &block) ⇒ Object
Creates an object, instantly saves it as a record (if the validation permits it), and returns it. If the save fails under validations, the unsaved object is still returned.
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/ar-extensions/create_and_update.rb', line 173 def create_with_extension(attributes = nil, ={}, &block)#:nodoc: return create_without_extension(attributes, &block) unless .any? 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 |
#create_with_extension!(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.
187 188 189 190 |
# File 'lib/ar-extensions/create_and_update.rb', line 187 def create_with_extension!(attributes = nil, ={}, &block)#:nodoc: return create_without_extension!(attributes, &block) unless .any? create_with_extension(attributes, .merge(:raise_exception => true), &block) end |