Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Rails从Postgres中的DateTime列计算精确的持续时间_Ruby On Rails_Ruby_Irb_Pry_Rails Console - Fatal编程技术网

Ruby on rails 使用Rails从Postgres中的DateTime列计算精确的持续时间

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

我试图得到一个更准确的输出比约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, 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"