问题
I am using time_select in a rails view, it looks something like this:
<div class="field">
<%= f.label :StartTime, "Start Time" %><br />
<%= f.time_select :StartTime %>
</div>
I want to set the default time to 09:00 (AM), how would I do that?
回答1:
What about setting corresponding model property?
def new
@session = Session.new
@session.StartTime = Time.now.beginning_of_day + 9.hours
end
Note that in Ruby it's against widely accepted conventions to name methods in PascalCase. StartTime
should become start_time
.
(I took the liberty of naming the model Session
, since you didn't specify any name).
来源:https://stackoverflow.com/questions/8695745/rails-time-select-set-default