diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 2806348337bb7c4180db20973c23bc93ce60a926..cf24f2753676ac1298d2f2f958983ddfb125572d 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -13,7 +13,7 @@ module Helpers # # * :prefix - overwrites the default prefix of "date" used for the select names. So specifying "birthday" # would give birthday[month] instead of date[month] if passed to the select_month method. - # * :include_blank - set to true if it should be possible to set an empty date. + # * :include_blank - set to true or to a prompt string if it should be possible to set an empty date. # * :discard_type - set to true if you want to discard the type part of the select name. If set to true, # the select_month method would use simply "date" (which can be overwritten using :prefix) instead # of "date[month]". @@ -887,7 +887,7 @@ def build_select(type, select_options_as_html) select_options.merge!(:disabled => 'disabled') if @options[:disabled] select_html = "\n" - select_html << content_tag(:option, '', :value => '') + "\n" if @options[:include_blank] + select_html << content_tag(:option, "#{ERB::Util.html_escape(@options[:include_blank]) if @options[:include_blank].kind_of?(String)}", :value => '') + "\n" if @options[:include_blank] select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt] select_html << select_options_as_html diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index fadfb59572eef1b2d6eb3625be8d9c7cd0af8b20..21c90833861d5e114fae36cee4f5b597021f9123 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1581,6 +1581,26 @@ def test_date_select_with_nil_and_blank assert_dom_equal expected, date_select("post", "written_on", :include_blank => true) end + def test_date_select_with_stringified_blank + @post = Post.new + + start_year = Time.now.year-5 + end_year = Time.now.year+5 + + expected = '' + "\n" + expected << %{\n" + + expected << %{\n" + + assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=> 'blank') + end + def test_date_select_with_nil_and_blank_and_order @post = Post.new