Installing the ODBC Adapter for Active Record / Ruby on Rails
Table of Contents
There are 2 ways to install the ODBC Adapter package, either as a gem (recommended) or by running the custom installation script. Pick one of the following methods, depending on whether you want the adapter to be available system-wide or just within a particular Rails project.
Installation as a Gem
Install the odbc-rails gem by running:
# gem install -r odbc-rails --include-dependencies
In version 1.5, you need to enable loading of the adapter by modifying your Rails project's config/environment.rb script to include it: immediately after the line
require File.join(File.dirname(__FILE__), 'boot')
i.e.
require File.join(File.dirname(__FILE__), 'boot')
RAILS_CONNECTION_ADAPTERS = %w{ odbc }
Manual installations
Having downloaded the adapter, unpack it into a temporary directory:
zsh, pizza 12:30PM ruby/ % tar xvpfz odbc-rails-1.5.tgz odbc-rails-1.5/ odbc-rails-1.5/support/ odbc-rails-1.5/support/pack_odbc.rb odbc-rails-1.5/support/odbc_rails.diff odbc-rails-1.5/support/lib/ odbc-rails-1.5/support/lib/active_record/ odbc-rails-1.5/support/lib/active_record/connection_adapters/ ... zsh, pizza 12:31PM ruby/ % cd ./odbc-rails-1.5 zsh, pizza 12:36PM odbc-rails-1.5/ % ls AUTHORS README lib/ COPYING Rakefile rdoc/ ChangeLog init.rb support/ LICENSE install.rb test/ NEWS install_odbc.rb
Become root and run `ruby install_odbc.rb' to copy the files into place:
zsh, pizza 12:34PM odbc-rails-1.5/ % su
Password:
zsh, pizza 12:36PM odbc-rails-1.5/ # ruby install_odbc.rb
<< Installation script for Rails ODBC Adapter >>
Checking if Locomotive is installed
Checking if RubyGems is installed.
Looking for installed ActiveRecord gems.
Target ActiveRecord directory for install:
[/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record]
Enter c to change target ActiveRecord directory, q to quit, i to install
...
./connection_adapters/odbc_adapter.rb -> /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/./connection_adapters/odbc_adapter.rb
chmod 0644 /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/./connection_adapters/odbc_adapter.rb
------------------------------------------------------------
Checking RAILS_CONNECTION_ADAPTERS (active_record.rb) includes odbc.
Copying active_record.rb to active_record.rb_2008_4_25
Patching active_record.rb.
Checking for Ruby ODBC Bridge.
WARNING>> odbc.bundle* is not present under:
/Applications/Locomotive.app
The Ruby ODBC Bridge must be installed before the Rails ODBC Adapter can be
used.
Done.
As shown above, the install script will automatically detect where your existing Active Record installation is located, whether you're using Locomotive on the Mac or not. (The above shows it running on Mac OS X Tiger with the default system-wide ruby installation paths.) Running it as `ruby install_odbc.rb' requires that you have the right ruby executable in your PATH - note that becoming root via su or sudo will change your environment variables so re-set it afterwards too.