出现“ :: prompt”问题在select_year中,以start / end_year为单位 [英] Issue with ":prompt" in select_year with start/end_year
问题描述
使用此答案作为指导,我着手创建一个 select_year
,该日期从今天的年份开始,到100年前结束。但是我想添加一个:prompt
,以便下拉列表以 Year(年份)而不是当前年份开始。因此,我使用了以下内容:
Using this answer as a guide, I set out to create a select_year
that started with today's year and ends 100 years ago. But I wanted to add a :prompt
so that the drop down starts with "Year" instead of the current year. So I used the following:
<%= select_year(Date.today, {:prompt => "Year", :start_year => DateTime.now.year, :end_year => DateTime.now.year - 115}, {:field_name => 'Year', :id => 'Date.year'}) %>
这会导致年份下降,但提示显示的是当前年份而不是年份。但是,如果我单击下拉列表,它将显示年份作为选择当前年份的第一个选项。我怎样才能解决这个问题?我做错了什么?
This renders a drop down for year, but the prompt shows current year instead of "Year". If I click the drop down though, it shows "Year" as the first option with current year selected. How can I fix this? What did I do wrong?
更新:这是上面代码的HTML输出:
UPDATE: Here is the HTML output of the above code:
<select field_name="Year" id="Date.year" name="date[year]">
<option value="">Year</option>
<option selected="selected" value="2011">2011</option>
如何做到这一点,所以2011年不会自动 selected
?
How can I make it so 2011 isn't automatically "selected"
?
推荐答案
解决方案很简单
<%= select_year(0, {:prompt => "Year",
:start_year => DateTime.now.year,
:end_year => DateTime.now.year - 115},
{:field_name => 'Year', :id => 'Date.year'}) %>
如果默认值超出范围,我建议您先选择提示提示符的列表
I suppopse if default value is out of range you have first of the list selected which is prompt
这篇关于出现“ :: prompt”问题在select_year中,以start / end_year为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!