How to change how ActiveAdmin displays time (every time)

前端 未结 3 1844
自闭症患者
自闭症患者 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条回答
  •  悲&欢浪女
    2021-02-05 14:32

    I've found there are two ways to do this:

    1. Javascript

    This is the easier method because it is very short and doesn't involve adding a db field. It works because it uses the users timezone from their browser. This answer gives insight on how to do this.

    2. From the Database

    This process can be found in this railscast.

    Essentially store a time_zone field in the users table. Then use an before_filter (although an around_filter might be a better idea) to set the timezone in the controller.

    before_filter :set_time_zone
    
    private
    def set_time_zone
      Time.zone = current_user.time_zone if current_user
    end
    

提交回复
热议问题