I’ve got two attributes start_time and end_time.
How can I use the date (excluding the time) that was entered for the start_time to be included into the end_time field (as the start+end times will occur on the same day, so there is no point prompting the user to enter it twice).
View:
<div class="day">
<div class="field">
<%= f.label :start_time, "Date" %>
<%= f.date_select :start_time,:default => Time.now+1.week, :order => [:month, :day, :year], :ampm => true %>
</div>
<div class="field">
<%= f.label :start_time, "Start Time" %>
<%= f.time_select :start_time, :ignore_date => true, :minute_step => 15, :ampm => true, :default => Time.now.beginning_of_day + 9.hours %>
</div>
<div class="field">
<%= f.label :end_time, "End Time" %>
<%= f.time_select :end_time, :minute_step => 15, :ampm => true, :default => Time.now.beginning_of_day + 15.hours %>
</div>
<%= link_to_function "Remove this day", "remove_fields(this)" %>
</div>
Any help would be appreciated.
There isn’t really a neat way to do this. You will have to extract the individual components:
Be aware of which time zone you are working in. You may need to use
Time.utcinstead ofTime.local.