我有一个time_select,我在其中设置时间值如下;
<%= f.time_select :start_time, :value => (@invoice.start_time ? @invoice.start_time : Time.now) %>
Run Code Online (Sandbox Code Playgroud)
这总是产生一个时间选择器,其中包含当前时间而不是@ invoice.start_time的值.
@ invoice.start_time实际上是一个datetime对象,但如果我使用的话,这会被传递给时间选择器
<%= f.time_select :start_time %>
Run Code Online (Sandbox Code Playgroud)
我想我真正想问的是如何使用:value选项和time_select帮助器.像下面这样的尝试似乎没有产生预期的结果;
<%= f.time_select :start_time, :value => (Time.now + 2.hours) %>
<%= f.time_select :start_time, :value => "14:30" %>
Run Code Online (Sandbox Code Playgroud)