我有一个变量@the_date
和一个没有关联模型的 date_select 表单助手。
如何使用date_select
来显示相应的 HTML?
以下不起作用:
<%= date_select "the_date", @the_date %>
我有一个变量@the_date
和一个没有关联模型的 date_select 表单助手。
如何使用date_select
来显示相应的 HTML?
以下不起作用:
<%= date_select "the_date", @the_date %>
你可以做:
<% @the_date = Time.now %>
<%= date_select("my_date", "my_date", :default => @the_date) %>
这是最终奏效的方法:
<% @the_date = Date.strptime(@the_date_string, "%Y-%m-%d") %>
<%= date_select("the_date_string", "", :default => @the_date) %>
我将日期存储为字符串。因此,在以 HTML 表单显示之前,需要将其转换为日期对象,并在保存到数据库之前转换回字符串。