Skip to content

Instantly share code, notes, and snippets.

@spastorino
Created February 25, 2010 03:38
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 spastorino/314204 to your computer and use it in GitHub Desktop.
Save spastorino/314204 to your computer and use it in GitHub Desktop.
*_select for date_helper
module ActionView
module Helpers
module DateHelper
[:second, :minute, :hour, :day, :month, :year].each do |name|
self.module_eval(<<-EOS)
def #{name.to_s}_select(object_name, method, options = {}, html_options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_#{name.to_s}_select_tag(options, html_options)
end
EOS
end
end
class InstanceTag
[:second, :minute, :hour, :day, :month, :year].each do |name|
self.class_eval(<<-EOS)
def to_#{name.to_s}_select_tag(options = {}, html_options = {})
datetime_selector(options, html_options).select_#{name.to_s}.html_safe!
end
EOS
end
end
class FormBuilder
[:second, :minute, :hour, :day, :month, :year].each do |name|
self.class_eval(<<-EOS)
def #{name.to_s}_select(method, options = {}, html_options = {})
@template.#{name.to_s}_select(@object_name, method, objectify_options(options), html_options)
end
EOS
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment