How do I set a time in a time_select view helper?
Posted
by brad
on Stack Overflow
See other posts from Stack Overflow
or by brad
Published on 2010-04-19T01:44:39Z
Indexed on
2010/04/19
1:53 UTC
Read the original article
Hit count: 366
I have a time_select in which I am trying to set a time value as follows;
<%= f.time_select :start_time, :value => (@invoice.start_time ? @invoice.start_time : Time.now) %>
This always produces a time selector with the current time rather than the value for @invoice.start_time.
@invoice.start_time is in fact a datetime object but this is passed to the time selector just fine if I use
<%= f.time_select :start_time %>
I guess what I'm really asking is how to use the :value option with the time_select helper. Attempts like the following don't seem to produce the desired result;
<%= f.time_select :start_time, :value => (Time.now + 2.hours) %>
<%= f.time_select :start_time, :value => "14:30" %>
© Stack Overflow or respective owner