class ActiveRecord::Associations::CollectionAssociation
Public Instance Methods
build(attributes = {}, options = {}) { |record| ... }
click to toggle source
# File lib/active_record/mass_assignment_security/associations.rb, line 23 def build(attributes = {}, options = {}, &block) if attributes.is_a?(Array) attributes.collect { |attr| build(attr, options, &block) } else add_to_target(build_record(attributes, options)) do |record| yield(record) if block_given? end end end
build_record(attributes, options)
click to toggle source
Calls superclass method
# File lib/active_record/mass_assignment_security/associations.rb, line 62 def build_record(attributes, options) previous = klass.current_scope(true) if block_given? super ensure klass.current_scope = previous if previous end
create(attributes = {}, options = {}, &block)
click to toggle source
# File lib/active_record/mass_assignment_security/associations.rb, line 33 def create(attributes = {}, options = {}, &block) create_record(attributes, options, &block) end
create!(attributes = {}, options = {}, &block)
click to toggle source
# File lib/active_record/mass_assignment_security/associations.rb, line 37 def create!(attributes = {}, options = {}, &block) create_record(attributes, options, true, &block) end
Private Instance Methods
create_record(attributes, options, raise = false) { |record| ... }
click to toggle source
# File lib/active_record/mass_assignment_security/associations.rb, line 41 def create_record(attributes, options, raise = false, &block) unless owner.persisted? raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved" end if attributes.is_a?(Array) attributes.collect { |attr| create_record(attr, options, raise, &block) } else transaction do add_to_target(build_record(attributes, options)) do |record| yield(record) if block_given? insert_record(record, true, raise) end end end end