0

我有一个应用程序帽子需要每 5 分钟更新一次,我在应用程序控制器中有这个:

# update last action & yet to implement updating vitals
def page_update
  if current_user
    current_user.last_page_load = DateTime.now
    interval = 300
    ime_difference = Time.now.to_i - current_user.vitals_update
    updates = time_difference / interval
    # use updates as a multiplier here for any data

    current_user.vitals_update = Time.now.to_i
    current_user.save
  end
end

目的是存储上次更新的时间戳并计算任何更改的乘数。某些原因我遇到了时间戳问题,我不知道该怎么做。

我试过输出没有运气的值,当我尝试设置时似乎

current_user.vitals_update = Time.now.to_i

我收到一条错误消息

387426 的未定义方法“更改”:Fixnum

4

1 回答 1

0

对于这种任务,最好使用 railstouch方法,如this answer中所述。
Rails 2.3.2 中的“触摸”updated_at 列

于 2013-02-08T17:16:24.400 回答