我有一个需要使用当前时间的Rails 3应用程序。管理员每次使用函数populateTable
时,lastPopulation
变量都需要更新到当前时间。两个问题:
1)我怎样才能最初将lastPopulation
变量设置为当前时间?
2)每当调用@lastUpdate = Time.now
方法时,是否有类似于populateTable
的赋值?
感谢所有帮助。感谢!!!
答案 0 :(得分:2)
您可以编写after_filter来设置lastPopulation,比如
after_filter :set_last_polulated, :only => ['populateTable']
def set_last_polulated
@lastPolulation = DateTime.now
end
答案 1 :(得分:0)
您好像在寻找DateTime#current
lastPopulation = DateTime.current