Ruby将变量初始化为当前时间

时间:2015-05-27 14:08:34

标签: ruby-on-rails ruby time updates

我有一个需要使用当前时间的Rails 3应用程序。管理员每次使用函数populateTable时,lastPopulation变量都需要更新到当前时间。两个问题:

1)我怎样才能最初将lastPopulation变量设置为当前时间?

2)每当调用@lastUpdate = Time.now方法时,是否有类似于populateTable的赋值?

感谢所有帮助。感谢!!!

2 个答案:

答案 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