Forum: Ruby on Rails using AR outside of 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.
F48118fe74b0c7f6fd82a0ee422fa34e?d=identicon&s=25 snacktime (Guest)
on 2007-03-04 04:53
(Received via mailing list)
I've seen a number of ways to use AR outside of rails, and am
wondering what other think is the best approach for my particular
application.

The application is in it's own module namespace.  To use it within
rails you just require it in application.rb and instantiate a class to
call methods on.  It's also well suited to be used from other various
applications though.   The simplest way I could think of to make my
application work inside and outside of rails without much user
intervention would be something like this.

require 'activerecord'
if ENV and ENV.has_key?('RAILS_ENV')
  require 'models/mymodel'
  ActiveRecord::Base.establish_connection()
end

I'd probably use a yaml file to store the database configuration like
rails does.

Any better ideas?
F48118fe74b0c7f6fd82a0ee422fa34e?d=identicon&s=25 snacktime (Guest)
on 2007-03-04 04:56
(Received via mailing list)
On 3/3/07, snacktime <snacktime@gmail.com> wrote:
>
>
Argh that should have been:
unless ENV and ENV.has_key?('RAILS_ENV')
This topic is locked and can not be replied to.