How to format datetime field in Ruby on Rails ActiveAdmin form?

I am using Ruby 2.1 and Rails 4.1. I installed ActiveAdmin (1.0.0.pre2). I want to format the datetime field expires_atin the form of ActiveAdmin. I tried this in /app/admin/job.rbusing the jQuery datepicker parameter:

f.input :expires_at, as: :datepicker, datepicker_options: { date_format: "yy-mm-dd", min_date: Time.to_s + "+7D" }

It works great as a new mode /admin/jobs/new, but it doesn't work in edit mode /admin/jobs/xx/edit. It always shows the value from db, for example 2015-11-06 15:10:00 UTC.

I also tried with :value, but it doesn't work either.

f.input :expires_at, :value => :expires_at.try(:strftime, '%Y-%m-%d'), as: :datepicker, datepicker_options: { min_date: Time.to_s + "+7D" }

I also have the following configuration in /config/locales/en.yml. However, I believe that this does not affect such form datetime fields.

en:
  date:
    formats:
      long: "%Y-%m-%d"
  time:
    formats:
      long: "%Y-%m-%d %H:%M"
+4
1

SO value input_html formtastic.

f.input :expires_at, :input_html => { :value => f.object.expires_at.try(:strftime, '%Y-%m-%d') }
+3

Source: https://habr.com/ru/post/1611169/


All Articles