How do you do relative time in Rails?

前端 未结 11 1604
借酒劲吻你
借酒劲吻你 2020-12-02 03:43

I\'m writing a Rails application, but can\'t seem to find how to do relative time, i.e. if given a certain Time class, it can calculate \"30 seconds ago\" or \"2 days ago\"

11条回答
  •  我在风中等你
    2020-12-02 04:38

    I've written a gem that does this for Rails ActiveRecord objects. The example uses created_at, but it will also work on updated_at or anything with the class ActiveSupport::TimeWithZone.

    Just gem install and call the 'pretty' method on your TimeWithZone instance.

    https://github.com/brettshollenberger/hublot

提交回复
热议问题