Skip to content

Instantly share code, notes, and snippets.

@kakra
Created November 29, 2009 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakra/245093 to your computer and use it in GitHub Desktop.
Save kakra/245093 to your computer and use it in GitHub Desktop.
tableless ActiveRecord models
# Tableless ActiveRecord models
# http://stackoverflow.com/questions/315850/rails-model-without-database/318919#318919
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