From: Brian Candler Date: 2009-08-18T19:32:52+09:00 Subject: Re: External Model Definition Using ActiveRecord Elizabeth wrote: > I've been Googling this topic, and I haven't found the answer. > > In Rails, the Models are defined in external files. How do you use > externally defined models in Ruby using ActiveRecord. I have a rails > app and a ruby app which will share the model definitions. I want to > use the DRY technique, so I don't want to define them both in the > models directory and inside the Ruby application. At simplest, just load them: require 'rubygems' require 'active_record' require 'app/models/foo' require 'app/models/bar' However you still need to establish_connection to the database in your app. Alternatively you may decide to bootstrap the entire Rails environment, which you can do most easily by running your script like so: script/runner myscript.rb Then it will use the config/database.yml entries to connect to the database as well. Also, you can use script/console to get an irb session with the models already wired up. -- Posted via http://www.ruby-forum.com/.