Rails time_select set default

爷,独闯天下 提交于 2019-12-12 02:29:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!