Skip to content

Instantly share code, notes, and snippets.

@kent
Created April 12, 2010 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kent/363798 to your computer and use it in GitHub Desktop.
Save kent/363798 to your computer and use it in GitHub Desktop.
Hi all.
Trying to do this
class Person < ActiveRecord::Base
include EasySelectFields
easy_select_fields "status", ["Interested", "Not Interested", "Available"]
end
module EasySelectFields
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def easy_select_fields(a,options)
type_method_name = "#{a}_types".to_sym
instance_eval do
def type_method_name
arr = []
count = 1
options.each do |o|
arr << [o,count]
count += 1
end
arr
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment