Created
December 1, 2008 02:12
-
-
Save brianleroux/30593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fucking around to hack together the most ghetto date_select known to man | |
require 'date' | |
def date_select( field, options={} ) | |
# wraps content with a specified tag | |
def rapper(tag, options={}) | |
"<#{ tag }>#{ yield if block_given? }</#{ tag }>" | |
end | |
# returns a correctly ordered array from a range | |
ranger = lambda do |from,to| | |
if from > to | |
c = "(#{ to }..#{ from }).to_a.reverse" | |
else | |
c = "(#{ from }..#{ to }).to_a" | |
end | |
return eval(c) | |
end | |
year = rapper(:select) do | |
ranger.call(DateTime.now.year, 1978).map { |x| rapper(:option){ x }} | |
end | |
month = rapper(:select) do | |
ranger.call(1,12).map { |x| rapper(:option){ x }} | |
end | |
day = rapper(:select) do | |
ranger.call(1,31).map { |x| rapper(:option){ x }} | |
end | |
"#{ year }#{ month }#{ day }" | |
end | |
puts date_select('foo') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment