开发者

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

开发者 https://www.devze.com 2023-04-05 23:32 出处:网络
Is there any option for formtastic in Active Admin, for the showing current datetime in datetime input. It\'s coming with bla开发者_JS百科nk on the form load.There is no direct way to do this. However

Is there any option for formtastic in Active Admin, for the showing current datetime in datetime input. It's coming with bla开发者_JS百科nk 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

0

精彩评论

暂无评论...
验证码 换一张
取 消