简体   繁体   中英

Format date in ActiveAdmin form

I got a list of trips which I display in ActiveAdmin, the index uses a formats.fr.yml and the date is displayed with the right format. However, when I modify a trip, in the form, ActiveAdmin doesn't use formats.fr.yml anymore. Here is the line in the form :

f.input :start_date, as: :date_time_picker

I tried something like this :

f.input :start_date, as: :date_time_picker, :value => :start_date.strftime('%d-%m-%Y %I:%M')

But it doesn't work. By the way, when I change the date with the datepicker, it changes the date to the right format (but because of some js).

Thanks for your help.

Try this one,

f.input :start_date, :value => :start_date.try(:strftime,'%y-%m-%d %i:%m')

Where try will prevent you from getting exceptions, when date is nil.

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