# Utility App using rails models

**URL:** <https://www.ruby-forum.com/t/utility-app-using-rails-models/96227>\
**Category:** Rails\
**Created:** [June 27, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/utility-app-using-rails-models/96227 "2006-06-27T15:05:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [June 27, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/utility-app-using-rails-models/96227/1 "2006-06-27T15:05:35Z")

</div>

I have a few maintenance programs that run periodically via cron. I  
learned how to use rails model files in those apps w/o much problem.  
However, the problem came about when one of my models, then many of  
my models began using plugins. Now I find that with each new plugin I  
use in my models, I have to go back to each of my utility apps and  
specifically require that plugin in order for the new model file to  
work.

Does anyone have an easier way? My current method is something like:

# Database

require ‘rubygems’  
require\_gem ‘activerecord’

require ‘…/…/vendor/plugins/acts\_as\_logged/lib/acts\_as\_logged’  
require ‘db\_connection’  
require ‘…/models/claim’  
require ‘…/models/mbr\_item\_category’

… code …

db\_connection is just a little helper file I created so that all my  
utils can be centrally configured to connect to the database, it  
looks something like:

ActiveRecord::Base.establish\_connection({  
:adapter =\> “postgresql”,  
:database =\> ‘ips2\_development’,  
})

So, see the problem with acts\_as\_logged?

Thanks for any info,

Jeremy C.

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [June 27, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/utility-app-using-rails-models/96227/2 "2006-06-27T15:11:37Z")

</div>

ISTR that if you put your ruby files (‘maintenance programs’) under your  
rails directory, and launch them with \<RAILS\_APP\>/script/runner you get  
all the rails environment available to your ruby program.

See here:  
[http://wiki.rubyonrails.org/rails/pages/HowToRunBackgroundJobsInRails](http://wiki.rubyonrails.org/rails/pages/HowToRunBackgroundJobsInRails)
