Loading a model into a cron file, in Rails

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

What's the best place to put my cron file?

edit: I am trying to execute a cron file like ruby ​​cron.rb

+1


a source to share


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







All Articles