Skip to content

Instantly share code, notes, and snippets.

@sher
Created March 25, 2011 09:25
Show Gist options
  • Save sher/886598 to your computer and use it in GitHub Desktop.
Save sher/886598 to your computer and use it in GitHub Desktop.
Tableless models in Rails 3
class BaseModel < 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
def save(validate = true)
validate ? valid? : true
end
end
class FormQuery < BaseModel
column :date_from, :date
column :date_until, :date
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment