如何在Rails 3中每个星期天增加变量?

时间:2012-10-01 07:49:23

标签: ruby-on-rails windows

我需要每个星期天增加一些柜台的价值。

我知道,如果今天是星期天,我可以通过以下代码获得:

def count
 @counter = 27226
  if Time.now.sunday?
    @counter +=315
  end
end

但它只会在星期日增加,而在其他日子它会相同,而不会增加。

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

Windows没有cron,但它确实有一个等效的任务调度程序。

请参阅调度程序的this overviewthis specific example以配置“仅限星期三”任务。

您所描述的计数器确实看起来像您通常存储在数据库中的那种值,例如: SQLite轻巧/方便。您可以查看this nice intro on SQLite in Windows

<强>更新

在评论中回答你的问题......

  

所以我可以运行.rb文件或ruby任务吗?

是的,你可以。这是一个小秘方:

1)使用此安装程序安装Ruby:http://rubyinstaller.org/ 注意:确保选中设置它的复选框,以便能够按原样运行独立的Ruby脚本。

2)编写示例ruby脚本以定期运行。例如,这里将抛出一个Windows对话框:

require 'Win32API'
title = "Test"
text = "Testing..."
dialog = Win32API.new('user32', 'MessageBox', 'LPPL', 'I')
result = dialog.call(0, text, title, 1)

3)以下是cmd.exe中“cron”设置的示例:     schtasks / create / sc minute / mo 1 / tn“测试脚本”/ tr c:\ Users \ manzoid \ dev \ test.rb