Loading a model into a cron file, in Rails
1 answer
I am assuming that you want to run the script (which you saved in the folder cron
) as a cronjob, but you want to load the Rails environment, including accessing your ActiveRecord models, before it runs.
If so, then you want to use the script/runner
script in your Rails app by giving it the name of the script you want to run, like
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 command crontab -e
and supply something like the following:
* * * * * /path/to/my/app/script/runner /path/to/my/app/cron/my_cron_script.rb
+4
a source to share