开发者

Comparison of String with ActiveSupport::Duration failed for time_ago_in_words

开发者 https://www.devze.com 2022-12-10 00:26 出处:网络
I get this error when I try to use time_ago_in_words: Comparison of String with ActiveSupport::Duration failed

I get this error when I try to use time_ago_in_words:

Comparison of String with ActiveSupport::Duration failed

I'm trying to check whether an object was created more than 8 minutes ago:

  <% if 开发者_开发百科time_ago_in_words(obj.created_at) > 8.minutes  %>
    <p>Yes</p>
  <% end %>

Would appreciate it if anyone knows the correct way to perform this test.


time_ago_in_words returns a phrase meant to be used in your UI. If you're comparing dates with each other, you're going to want to do it before it's translated into a user-friendly string.

Also note that I used minutes.ago in order to compare apples with apples.

<% if obj.created_at > 8.minutes.ago  %>
    Within the last 8 minutes
<% else %>
    Longer than 8 minutes ago
<% end %>
0

精彩评论

暂无评论...
验证码 换一张
取 消