public Method

DateHelper.select_hour(datetime, options = {})

Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. The hour can also be substituted for a hour number. Override the field name using the :field_name option, ‘hour’ by default.

Examples

my_time = Time.now + 6.hours

# Generates a select field for minutes that defaults to the minutes for the time in my_time
select_minute(my_time)

# Generates a select field for minutes that defaults to the number given
select_minute(14)

# Generates a select field for minutes that defaults to the minutes for the time in my_time
# that is named 'stride' rather than 'second'
select_minute(my_time, :field_name => 'stride')

Source Code

# File action_view/helpers/date_helper.rb, line 399
def select_hour(datetime, options = {})
  val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.hour) : ''
  if options[:use_hidden]
    hidden_html(options[:field_name] || 'hour', val, options)
  else
    hour_options = []
    0.upto(23) do |hour|
      hour_options << ((val == hour) ?
        %(<option value="#{leading_zero_on_single_digits(hour)}" selected="selected">#{leading_zero_on_single_digits(hour)}</option>\n) :
        %(<option value="#{leading_zero_on_single_digits(hour)}">#{leading_zero_on_single_digits(hour)}</option>\n)
      )
    end
    select_html(options[:field_name] || 'hour', hour_options.join, options)
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.