4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/datetime_helpers.rb', line 4
def datetime_select_tags(name, options)
v = options[:value] || Time.zone.now
c = options[:class]
id = options[:id]
s = []
s << "<style>.datetime select { width: auto }</style>"
s << "<span id=\"#{id if id}\" class=\"datetime #{c if c}\">"
s << select_tag(:"#{name}[day]", :options => (1..31).to_a, :selected => v.day )
s << select_tag(:"#{name}[month]", :options => Date::MONTHNAMES[1..-1].each_with_index.map { |x,i| [x,i+1] }, :selected => v.month)
s << select_tag(:"#{name}[year]", :options => (2012..2020).to_a, :selected => v.year )
s << '@'
s << select_tag(:"#{name}[hour]", :options => (0..23).to_a.map { |x| [x < 10 ? "0#{x}" : x,x] }, :selected => v.hour )
s << ':'
s << select_tag(:"#{name}[min]", :options => (0..59).to_a.map { |x| [x < 10 ? "0#{x}" : x,x] }, :selected => v.min )
s << '</span>'
s.join(' ')
end
|