简体   繁体   中英

Rails Active Admin datetime input does not load the current date and time?

Is there any option for formtastic in Active Admin, for the showing current datetime in datetime input. It's coming with blank on the form load.

There is no direct way to do this. However there are multiple options to do this

1- if you want to go with default feature provided by formtastic(drop down type time selection) then in the model class:

def after_initialize
  self.start_time ||= Time.now
end

Then when the form is displayed, it will already have the time populated and set correctly.

2- if you want to just show date then you can use

f.input :start_time, :as => :datepicker, :html_option => { value: Time.now }

3- use https://github.com/activeadmin-plugins/active_admin_datetimepicker gem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM