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
I’m assuming what you want to do is run a script (which you have saved in the
cronfolder) 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/runnerscript in your Rails app, supplying it with the name of the script you want to run, e.g.If you want to add this as a cronjob, add it to your crontab as follows. Edit your crontab with the
crontab -ecommand and put something like the following there: