2

我有一个变量@the_date和一个没有关联模型的 date_select 表单助手。

如何使用date_select来显示相应的 HTML?

以下不起作用:

<%= date_select "the_date", @the_date %>
4

2 回答 2

3

你可以做:

<% @the_date = Time.now %>
<%= date_select("my_date", "my_date", :default => @the_date) %>
于 2011-09-23T06:04:35.673 回答
2

这是最终奏效的方法:

<% @the_date = Date.strptime(@the_date_string, "%Y-%m-%d") %>
<%= date_select("the_date_string", "", :default => @the_date) %>

我将日期存储为字符串。因此,在以 HTML 表单显示之前,需要将其转换为日期对象,并在保存到数据库之前转换回字符串。

于 2011-09-23T08:01:00.260 回答