I need to store data from a cron job in Ruby on Rails so that my controllers can still access it. I'm not too sure what the best way is to do this. By the way I'm a Ruby on Rails newb, so perhaps what I'm asking is extremely simple.
2 Answers
Check this out http://railscasts.com/episodes/164-cron-in-ruby (there is a revised version, but you have to pay $9 aprox. per month for pro videos).
You can make a task or a runner so you can access to ActiveRecord and store the data into some model.
For runners in Rails: http://guides.rubyonrails.org/command_line.html#rails-runner For tasks: http://erik.debill.org/2011/12/04/rake-for-rails-developers
Also, if you use tasks (which I recommend) watch this entry: Do rails rake tasks provide access to ActiveRecord models?

- 1
- 1

- 2,087
- 2
- 22
- 35
One way to store the results of you cron job is the create a controller with basic authentication if you care about the security of your results.
See the API.
So after you save your results from you cron say to /tmp/myresults
, you can post via
curl -d @/tmp/myresults http:/myrailsapplcaition.com:3000:/path_tomypost_method