Using the rails configuration outside rails

I have a ruby class that will be used sometimes from within rails, and
sometimes from without (not in the context of a running rails
application).
It will reference models within the rails app, and It may be run
manually,
or may be scheduled via Cron (though I may look at RailsCron as well).
I’ve
seen help on the Wiki for using models outside of Rails (like this
articlehttp://wiki.rubyonrails.com/rails/pages/HowToUseActiveRecordOutsideRails),
but I’d rather not repeat my database configuration. Is there a better
way
to do this?

Am Freitag, den 03.03.2006, 22:58 -0600 schrieb Larry W.:

I have a ruby class that will be used sometimes from within rails, and
sometimes from without (not in the context of a running rails
application). It will reference models within the rails app, and It
may be run manually, or may be scheduled via Cron (though I may look
at RailsCron as well). I’ve seen help on the Wiki for using models
outside of Rails (like this article), but I’d rather not repeat my
database configuration. Is there a better way to do this?

ENV[‘RAILS_ENV’] = ARGV.first || ‘development’
require File.dirname(FILE) + ‘/…/…/config/boot’
require RAILS_ROOT + ‘/config/environment’

I am using this few lines to load the Rails environment. After that
code, you have a full functional rails environment. You can specify
‘production’ or ‘development’ mode as the first argument passed to the
script. Don’t forget to adjust the relative path in line 2 to your
needs.

Norman T.

http://blog.inlet-media.de

On 3/4/06, Norman T. [email protected] wrote:

ENV[‘RAILS_ENV’] = ARGV.first || ‘development’

http://blog.inlet-media.de


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

That worked perfectly. Thanks.