class method
self.new
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v3.2.22.5Signature
self.new(attributes = nil)
New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass a hash with key names matching the associated table column names). In both instances, valid attribute keys are determined by the column names of the associated table – hence you can’t have attributes that aren’t part of the table columns.
Parameters
-
attributesopt = nil
Source
# File activerecord/lib/active_record/base.rb, line 2280
def initialize(attributes = nil)
@attributes = attributes_from_column_definition
@attributes_cache = {}
@new_record = true
ensure_proper_type
self.attributes = attributes unless attributes.nil?
self.class.send(:scope, :create).each { |att,value| self.send("#{att}=", value) } if self.class.send(:scoped?, :create)
result = yield self if block_given?
callback(:after_initialize) if respond_to_without_attributes?(:after_initialize)
result
end
Defined in activerecord/lib/active_record/base.rb line 2280
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base