B S*_*ven 3 ruby-on-rails form-helpers ruby-on-rails-3
以下代码按预期工作,使用@the_date作为默认选定日期.
<%= date_select("the_date", "", :default => @the_date ) %>
Run Code Online (Sandbox Code Playgroud)
但是,如果没有日期,则需要显示空白.以下代码显示空白,但即使定义了日期,也会强制默认选择为空白.
<%= date_select("patient_details[birth_date]", "", { :default => @the_date, :include_blank => true } ) %>
Run Code Online (Sandbox Code Playgroud)
如何将默认选择设置为日期,如果日期为零则将其设置为空白?
在Rails 3.07中工作.
谢谢.
只是,:include_blank => @ the_date.nil?,它应该做的伎俩.见下面的例子
date_select(:patient_details, :birth_date, { :default => @the_date, :include_blank=> @the_date.nil? })
| 归档时间: |
|
| 查看次数: |
5359 次 |
| 最近记录: |