Skip to content

Instantly share code, notes, and snippets.

@miligraf
Created December 8, 2016 01:58
Show Gist options
  • Save miligraf/1c245617526ba98a69c5191e70ea1049 to your computer and use it in GitHub Desktop.
Save miligraf/1c245617526ba98a69c5191e70ea1049 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
class_attribute :columns
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
column :name, :text
column :country_id, :integer
belongs_to :country
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment