ENV[''RAILS_ENV''] = ''production'' require ''config/environment'' Model.do_something()
--- Ben Nolan <ben-tH0n/LiDeu9BWQWeTLFoew@public.gmane.org> wrote:> Hi, > > I have a cron job that I want to write in ruby. It > will pull a bunch of > stuff out of the rails database and dump it into a > csv file. It''s easy > enough to do in php / perl - but I''d rather stick to > doing it in ruby > (for simplicity) - does anyone have a skeleton > script that shows you how > to use active_record from the commandline? > > eg: > > ruby app/jobs/databasedump.rb >Modify script/console. Change irb to ruby and modify the way it handles ARGV. This should give you a rails environment for running ruby scripts from the shell. NOTE** I''ve not tested this, but I was planning on using it myself. Thanks, Andrew M. Campbell
--- "Andrew M. Campbell" <listdata-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:> > --- Ben Nolan <ben-tH0n/LiDeu9BWQWeTLFoew@public.gmane.org> wrote: > > Hi, > > > > I have a cron job that I want to write in ruby. It > > will pull a bunch of > > stuff out of the rails database and dump it into a > > csv file. It''s easy > > enough to do in php / perl - but I''d rather stick > to > > doing it in ruby > > (for simplicity) - does anyone have a skeleton > > script that shows you how > > to use active_record from the commandline? > > > > eg: > > > > ruby app/jobs/databasedump.rb > > > > Modify script/console. Change irb to ruby and > modify > the way it handles ARGV. This should give you a > rails > environment for running ruby scripts from the shell. > > NOTE** I''ve not tested this, but I was planning on > using it myself.OK, just tested it and was able to require one of my models and use its find_all method. Here is the modified version of script/console: http://andrewc.mdns.org/run_my_prog.txt Hope this helps
On March 12, 2005 08:40, Andrew M. Campbell wrote:> > --- Ben Nolan <ben-tH0n/LiDeu9BWQWeTLFoew@public.gmane.org> wrote: > > Hi, > > > > I have a cron job that I want to write in ruby. It > > will pull a bunch of > > stuff out of the rails database and dump it into a > > csv file. It''s easy > > enough to do in php / perl - but I''d rather stick to > > doing it in ruby > > (for simplicity) - does anyone have a skeleton > > script that shows you how > > to use active_record from the commandline? > > > > eg: > > > > ruby app/jobs/databasedump.rb > > > > Modify script/console. Change irb to ruby and modify > the way it handles ARGV. This should give you a rails > environment for running ruby scripts from the shell. > NOTE** I''ve not tested this, but I was planning on > using it myself. > > Thanks, > Andrew M. Campbell > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >I have written some scripts that use active record away from the rails framework. All you have to do is: require ''rubygems'' require_gem ''activerecord'' require ''your model files'' Connect to the database with ActiveRecord::Base.establish_connection(...) If you want AR to log its actions like it does in rails set the logger ActiveRecord::Base.logger = Logger.new(''filename'') Then you should be able to use your model classes like you would from a rails controller. Luca
Ben Nolan <ben-tH0n/LiDeu9BWQWeTLFoew@public.gmane.org> wrote:> I have a cron job that I want to write in ruby. It will pull a bunch of > stuff out of the rails database and dump it into a csv file. It''s easy > enough to do in php / perl - but I''d rather stick to doing it in ruby > (for simplicity) - does anyone have a skeleton script that shows you how > to use active_record from the commandline?When I''ve had to do this in PHP and Python, I''ve just written the code as a web application, then used curl in the cron job to "execute" the web page by opening the URL. If the program/script runs for more than 30 seconds you will have to turn off timeouts so the web server doesn''t give up on it. Greg Jorgensen PDXperts LLC Portland, Oregon, USA
Hi, I have a cron job that I want to write in ruby. It will pull a bunch of stuff out of the rails database and dump it into a csv file. It''s easy enough to do in php / perl - but I''d rather stick to doing it in ruby (for simplicity) - does anyone have a skeleton script that shows you how to use active_record from the commandline? eg: ruby app/jobs/databasedump.rb Regards, Ben