views:

282

answers:

1

I have a directory called cron, inside my app directory. In the cron directory, I have put my cron file. How do I access the model inside my cron file?

Which is the best place to put my cron file?

edit: I'm trying to execute the cron file, directly like ruby cron.rb

+3  A: 

I'm assuming what you want to do is run a script (which you have saved in the cron folder) as a cronjob, but you want it to load the Rails environment, including access to your ActiveRecord models, before it runs.

If this is the case, what you want to use is the script/runner script in your Rails app, supplying it with the name of the script you want to run, e.g.

script/runner cron/my_cron_script.rb

If you want to add this as a cronjob, add it to your crontab as follows. Edit your crontab with the crontab -e command and put something like the following there:

* * * * * /path/to/my/app/script/runner /path/to/my/app/cron/my_cron_script.rb
gar
thank you, that worked :-)