Using a duration field in a Rails model

前端 未结 4 1174
温柔的废话
温柔的废话 2021-01-30 07:00

I\'m looking for the best way to use a duration field in a Rails model. I would like the format to be HH:MM:SS (ex: 01:30:23). The database in use is sqlite locally and Postgr

4条回答
  •  遇见更好的自我
    2021-01-30 07:46

    I've wrote a some stub to support and use PostgreSQL's interval type as ActiveRecord::Duration.

    See this gist (you can use it as initializer in Rails 4.1): https://gist.github.com/Envek/7077bfc36b17233f60ad

    Also I've opened pull requests to the Rails there: https://github.com/rails/rails/pull/16919

提交回复
热议问题