instance method
create
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18 PrivateAvailable in: v2.2.3 v2.3.18
Signature
create()
Creates a record with values matching those of the instance attributes and returns its id.
Source
# File activerecord/lib/active_record/base.rb, line 2720
def create
if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name)
self.id = connection.next_sequence_value(self.class.sequence_name)
end
quoted_attributes = attributes_with_quotes
statement = if quoted_attributes.empty?
connection.empty_insert_statement(self.class.table_name)
else
"INSERT INTO #{self.class.quoted_table_name} " +
"(#{quoted_column_names.join(', ')}) " +
"VALUES(#{quoted_attributes.values.join(', ')})"
end
self.id = connection.insert(statement, "#{self.class.name} Create",
self.class.primary_key, self.id, self.class.sequence_name)
@new_record = false
id
end
Defined in activerecord/lib/active_record/base.rb line 2720
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base