Forum: Ruby on Rails Using the rails configuration outside rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
340fc2e514619a65816216c7a9fe6b1b?d=identicon&s=25 Larry Wright (Guest)
on 2006-03-04 06:01
(Received via mailing list)
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<http://wiki.rubyonrails.com/rails/pages/HowToUseAc...),
but I'd rather not repeat my database configuration. Is there a better
way
to do this?
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-04 10:50
(Received via mailing list)
Am Freitag, den 03.03.2006, 22:58 -0600 schrieb Larry Wright:
> 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 Timmler

http://blog.inlet-media.de
340fc2e514619a65816216c7a9fe6b1b?d=identicon&s=25 Larry Wright (Guest)
on 2006-03-05 15:10
(Received via mailing list)
On 3/4/06, Norman Timmler <lists@inlet-media.de> wrote:
> ENV['RAILS_ENV'] = ARGV.first || 'development'
>
> http://blog.inlet-media.de
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

That worked perfectly. Thanks.
This topic is locked and can not be replied to.