You can add ActiveRecord functionality to your classes by adding the following, assuming that you’ve got the ActiveRecord gem on your machine
1 require 'active_record'
2 class Widget < ActiveRecord::Base
3 end
In your client you’ll need to establish a connection to your database with something along these lines
1 dbconfig = YAML::load(File.open(File.dirname(__FILE__) + '/../config/database.yml'))
2 ActiveRecord::Base.establish_connection(dbconfig)
You can even have migrations using a Rake file in your project root that looks a bit like this
1 require 'active_record'
2 require 'yaml'
3
4 task :default => :migrate
5
6 desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
7 task :migrate => :environment do
8 ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
9 end
10
11 task :environment do
12 ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml')))
13 ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a'))
14 end
But if you’re looking for the fancier functionality such as ActsAsList or ActsAsTree then you’re going to have to do a bit of frigging as this functionality was removed from ActiveRecord (in Rails version 2.3.somethingorother) to make it more lightweight. The quickest way is to create a blank Rails project and install the desired functionality as a pluginscript/plugin install acts_as_tree
then copy the code fromvendor/plugins/acts_as_tree/lib/activerecord/acts/tree.rb
and place it into your projectlib/activerecord/acts/tree.rb
then in your model add the following
1 $:.unshift "#{File.dirname(__FILE__)}/../lib"
2 require 'active_record/acts/list'
3 ActiveRecord::Base.class_eval { include ActiveRecord::Acts::List }