capsctrldays

2006-06-09 (金) [長年日記]

[Rails] date_select に年, 月, 日を入れる

メモ

ActionView::Helpers::DateHelper.module_eval do
  private
  def select_html(type, options, prefix = nil, include_blank = false, discard_type = false, disabled = false)

    date_type_hash = {"year" => "年", "month"=> "月", "day" => "日" }

    select_html  = %(<select name="#{prefix || ActionView::Helpers::DateHelper::DEFAULT_PREFIX})
    select_html << "[#{type}]" unless discard_type
    select_html << %(")
    select_html << %( disabled="disabled") if disabled
    select_html << %(>\n)
    select_html << %(<option value=""></option>\n) if include_blank
    select_html << options.to_s
    select_html << "</select>\n"
    select_html << "#{date_type_hash[type]}"
  end
end