Class: ActiveRecord::BaseWithoutTable
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::BaseWithoutTable
- Defined in:
- lib/active_record/base_without_table.rb
Overview
Get the power of ActiveRecord models, including validation, without having a table in the database.
Usage
class Contact < ActiveRecord::BaseWithoutTable
column :name, :string
column :email_address, :string
column :message, :text
end
validates_presence_of :name, :email_address, :string
This model can be used just like a regular model based on a table, except it will never be saved to the database.
Class Method Summary collapse
-
.column(name, sql_type = nil, default = nil, null = true) ⇒ Object
:nodoc:.
-
.reset_column_information ⇒ Object
Do not reset @columns.
Instance Method Summary collapse
-
#create_or_update ⇒ Object
:nodoc:.
Class Method Details
.column(name, sql_type = nil, default = nil, null = true) ⇒ Object
:nodoc:
30 31 32 33 |
# File 'lib/active_record/base_without_table.rb', line 30 def column(name, sql_type = nil, default = nil, null = true) # :nodoc: columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) reset_column_information end |
.reset_column_information ⇒ Object
Do not reset @columns
36 37 38 39 |
# File 'lib/active_record/base_without_table.rb', line 36 def reset_column_information # :nodoc: generated_methods.each { |name| undef_method(name) } @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @generated_methods = nil end |
Instance Method Details
#create_or_update ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/active_record/base_without_table.rb', line 22 def create_or_update # :nodoc: errors.empty? end |