# How to run a cpu intensive ruby script with rails functional

**URL:** <https://www.ruby-forum.com/t/how-to-run-a-cpu-intensive-ruby-script-with-rails-functional/103306>\
**Category:** Rails\
**Created:** [May 4, 2007, 1:10am UTC](https://www.ruby-forum.com/t/how-to-run-a-cpu-intensive-ruby-script-with-rails-functional/103306 "2007-05-04T01:10:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [May 4, 2007, 1:10am UTC](https://www.ruby-forum.com/t/how-to-run-a-cpu-intensive-ruby-script-with-rails-functional/103306/1 "2007-05-04T01:10:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [May 4, 2007, 1:22am UTC](https://www.ruby-forum.com/t/how-to-run-a-cpu-intensive-ruby-script-with-rails-functional/103306/2 "2007-05-04T01:22:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [May 4, 2007, 11:03am UTC](https://www.ruby-forum.com/t/how-to-run-a-cpu-intensive-ruby-script-with-rails-functional/103306/3 "2007-05-04T11:03:58Z")

</div>

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

Anthony
