Skip to content

Instantly share code, notes, and snippets.

@cmaujean
Created October 25, 2010 04:17
Show Gist options
  • Save cmaujean/644386 to your computer and use it in GitHub Desktop.
Save cmaujean/644386 to your computer and use it in GitHub Desktop.
rails 2 table-less active record model.
# class Foo < Tableless
# column :bar, :string
# column :baz, :datetime
# validates_presence_of :bar, :baz
# end
class Tableless < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
sql_type.to_s, null)
end
# Override the save method to prevent exceptions.
def save(validate = true)
validate ? valid? : true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment