Anyone knows how to call a Rails action from the command line? I have an action that would update the database. I can call it from a web browser: http://localhost:3000/radar/update_radar I want to create a cron job that would do this regularly Thanks Effie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Effie wrote:> Anyone knows how to call a Rails action from the command line? > > I have an action that would update the database. I can call it from a > web browser: > http://localhost:3000/radar/update_radar > > I want to create a cron job that would do this regularly > > Thanks > > EffieThere''s probably a more dignified way of doing it, but... ruby script/runner ''require "open-uri"; open("http://localhost:3000/radar/update_radar")'' ...ought to do it! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The proper way of doing this is to pull out the update code into a library (class under lib/), say RadarUpdater in lib/radar_updater.rb. Then you can access it easily from both a Controller and it''s accessible from the outside. Your cron-job would look like: * * * * * ruby /path/to/rails/deploy/script/runner -e production " RadarUpdater.run" and Controller: def some_action RadarUpdater.run end Jason On 7/9/07, Effie <effiegoenawan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Anyone knows how to call a Rails action from the command line? > > I have an action that would update the database. I can call it from a > web browser: > http://localhost:3000/radar/update_radar > > I want to create a cron job that would do this regularly > > Thanks > > Effie > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > ruby script/runner ''require "open-uri"; > open("http://localhost:3000/radar/update_radar")'' > > ...ought to do it!Without the new line! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---