ruby-on-railsruby-on-rails-4simple-form-for

setting default timestamp in simple_form_for rails


My simple_form_for has fields

<div><%= f.input :start_time %></div>
<div><%= f.input :end_time %></div>

start_time and end_time are my database columns in postgresql by default when i open the forms it takes the current time as default as select it on options. How to set the default time which is 02:14(current time for start & end time) in the screensort to 00:00

UI looks like this enter image description here

database column enter image description here


Solution

  • You could probably best do this in the controller method for new:

    def new
      @model = Model.new
      @model.start_time = Time.now.beginning_of_day
      @model.end_time = Time.now.beginning_of_day
    end
    

    If I'm not mistaking, this should set the standard date to today, but at 00:00 hours.