How to change how ActiveAdmin displays time (every time)

前端 未结 3 1850
自闭症患者
自闭症患者 2021-02-05 13:59

Since the default time in the database is in utc, I wanted to be able to still display it in the users correct time. To do this I had to take column :created_at and

3条回答
  •  猫巷女王i
    2021-02-05 14:38

    You can target just ActiveAdmin by telling it to always use a particular filter in config/initializers/active_admin.rb , by adding a line like this:

    config.before_action :set_admin_timezone
    

    (or config.before_filter :set_admin_timezone for versions of Rails before Rails 4)

    Then in your ApplicationController, you can just define the method set_admin_timezone, and ActiveAdmin will use it. For example:

    def set_admin_timezone
      Time.zone = 'Eastern Time (US & Canada)'
    end
    

    You should be able look up the current admin user in that method (in order to get their particular timezone), but I haven't tried that.

提交回复
热议问题