Skip to content

Instantly share code, notes, and snippets.

@lexmag
Created July 5, 2012 19:32
Show Gist options
  • Save lexmag/3055907 to your computer and use it in GitHub Desktop.
Save lexmag/3055907 to your computer and use it in GitHub Desktop.
Virtual attributes #1
module VirtualAttributes
extend ActiveSupport::Concern
module ClassMethods
def attr_virtual(*attrs)
options = attrs.extract_options!
attrs.each do |attr|
class_eval do
send("attr_accessor", attr)
end
columns_hash[attr] = ActiveRecord::ConnectionAdapters::Column.new(attr, nil, options[:klass])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment