How to run a cpu intensive ruby script with rails functional

Hi All,

I am new to this list and to rails. So far I am loving the way in
which it is easy to put together web pages with a database backend.

I would love to use the rails functionality (to do the sql queries)
and then process the results using some very cpu intensuve tasks. The
results will take far longer than it is viable to use a web browser to
view the results. I would like to see the results on screen and write
them to file.

Is there a way of using rails functionality (specifically the model
aspect) in a standalone ruby script or from the console?

Many thanks

Anthony

Hi Ant,

You want to use AR outside of rails, no problem.

<<====test.rb
require ‘active_record’
class TardisBase < ActiveRecord::Base
self.abstract_class = true
establish_connection :adapter => ‘postgresql’,
:host => ‘localhost’,
:username => ‘me’,
:password => ‘secret’,
:database => ‘tardis’
end

class TimeMachineBase < ActiveRecord::Base
self.abstract_class = true
establish_connection :adapter => ‘postgresql’,
:host => ‘localhost’,
:username => ‘me’,
:password => ‘secret’,
:database => ‘timemachine’
end

class Person < TardisBase
end
class Groovy < TimeMachineBase
end

Person.find(:all).each do |person|

whatever

end
====test.rb

Hope this helps

Thanks Paul, that worked a real treat. After hours of google searching
this has solved it in minutes.

Anthony