public Method

DateHelper.select_day(date, options = {})

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

Examples

my_date = Time.today + 2.days

# Generates a select field for days that defaults to the day for the date in my_date
select_day(my_time)

# Generates a select field for days that defaults to the number given
select_day(5)

# Generates a select field for days that defaults to the day for the date in my_date
# that is named 'due' rather than 'day'
select_day(my_time, :field_name => 'due')

Source Code

# File action_view/helpers/date_helper.rb, line 432
def select_day(date, options = {})
  val = date ? (date.kind_of?(Fixnum) ? date : date.day) : ''
  if options[:use_hidden]
    hidden_html(options[:field_name] || 'day', val, options)
  else
    day_options = []
    1.upto(31) do |day|
      day_options << ((val == day) ?
        %(<option value="#{day}" selected="selected">#{day}</option>\n) :
        %(<option value="#{day}">#{day}</option>\n)
      )
    end
    select_html(options[:field_name] || 'day', day_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.