Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Forked from anonymous/gist:56969
Created February 2, 2009 16:36
Show Gist options
  • Save ELLIOTTCABLE/56970 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/56970 to your computer and use it in GitHub Desktop.
def generic_select (item, default, object, method, options = {})
obj = options[:object] || instance_variable_get("@#{object}")
value = options[:value] || (obj.nil? ? obj : obj.send(method))
value = value.to_s
options[:size] = options[:size] || default unless default.blank?
text_field(object, method, options) + '<div class="' + item + '_autocomplete autocomplete"></div>'
end
def generic_tag_select (item, default, name, value = nil, options = {})
value = value.to_s
options[:size] = options[:size] || default unless default.blank?
text_field_tag(name, value, options) + '<div class="' + item +'_autocomplete autocomplete"></div>'
end
set = {'customer'=>'','owner'=>'','patient'=>'','sales_person'=>'','make'=>'15','model'=>'15','size'=>'3','width'=>'3','supplier'=>'15'}
set.each do |item,default|
#Somewhere in here, I need to define item_tag_select and item_select for everything in the set
define_method "#{item}_select" do |arg, arg2|
# you can use 'default' in here
end
define_method "#{item}_tag_select" do |arg, arg2|
# you can use 'default' in here
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment