Time 在Rails 3中使用单词中的时间距离
我试图使用Rail的Time 在Rails 3中使用单词中的时间距离,time,Time,我试图使用Rail的distance\u of\u time\u(用单词表示)helper,但由于某种原因,我得到了一个未定义的方法错误。这是我的密码: 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.ag
distance\u of\u time\u(用单词表示)
helper,但由于某种原因,我得到了一个未定义的方法错误。这是我的密码:
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
def confirm_有配额
last_upload=当前_user.photos.last.created_at
剩余时间=时间的距离(大写)(1.day.ago,上次上传)
如果上次上传<1.day.ago
返回真值
其他的
flash[:error]=“每天允许您上传1次。请在“+剩余时间+”中重试”
将_重定向到(:返回)
结束
结束
这给了我“未定义的方法`单词中时间的距离'”。有人知道我做错了什么吗?谢谢。单词中的时间距离方法是ActionView助手,因此需要从视图(而不是控制器)调用
或者,您可以通过控制器内部的view\u上下文访问相同的内容
view_context.distance_of_time_in_words