Ruby on rails 使用Rails从Postgres中的DateTime列计算精确的持续时间
我试图得到一个更准确的输出比约2小时的持续时间 目前,我们使用的是单词中的time\u ago\u 这类似于.erb中的以下函数Ruby on rails 使用Rails从Postgres中的DateTime列计算精确的持续时间,ruby-on-rails,ruby,irb,pry,rails-console,Ruby On Rails,Ruby,Irb,Pry,Rails Console,我试图得到一个更准确的输出比约2小时的持续时间 目前,我们使用的是单词中的time\u ago\u 这类似于.erb中的以下函数 Duration: <%= time_ago_in_words(@sitrep.incident.created_at) %> # I found the gem `dotiw` which lets me use: distance_of_time_in_words(@sitrep.incident.created_at) # However, the
Duration: <%= time_ago_in_words(@sitrep.incident.created_at) %>
# I found the gem `dotiw` which lets me use:
distance_of_time_in_words(@sitrep.incident.created_at)
# However, there is an error and I can't get either to work in irb
关于如何进行有什么想法吗?为什么这在我们的rails项目中有效,而在irb中无效?为什么我不能让dotiw使用相同的输入?为什么我不能让taiw使用与生产中相同的输入来工作
谢谢 使用帮助程序,而不是手动包含帮助程序
> helper.time_ago_in_words(2.hours.ago, true)
=> "2 hours"
> helper.time_ago_in_words((2.hours.ago + 5.seconds), true)
=> "1 hour, 59 minutes, and 55 seconds"
Duration: about 2 hours
> helper.time_ago_in_words(2.hours.ago, true)
=> "2 hours"
> helper.time_ago_in_words((2.hours.ago + 5.seconds), true)
=> "1 hour, 59 minutes, and 55 seconds"