相关疑难解决方法(0)

如何在time_select视图助手中设置时间?

我有一个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)

views ruby-on-rails helpers time-select

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

helpers ×1

ruby-on-rails ×1

time-select ×1

views ×1