gpt4 book ai didi

time - 在 Rails 3 中使用 distance_of_time_in_words

转载 作者:行者123 更新时间:2023-12-04 19:31:14 27 4
gpt4 key购买 nike

我正在尝试使用 Rail 的 distance_of_time_in_words 助手,但由于某种原因我遇到了未定义方法错误。这是我的代码:

def confirm_has_quota
last_upload = current_user.photos.last.created_at
remaining_time = distance_of_time_in_words(1.day.ago, last_upload)
if last_upload < 1.day.ago
return true
else
flash[:error] = "You are allowed 1 upload per day. Please try again in" + remaining_time + "."
redirect_to(:back)
end
end

这给了我“未定义的方法‘distance_of_time_in_words’”。有人看到我在这里做错了吗?谢谢。

最佳答案

distance_of_time_in_words 方法是一个 ActionView Helper,因此需要从 View (而不是 Controller )调用。

http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html

关于time - 在 Rails 3 中使用 distance_of_time_in_words,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8355819/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com