I have ported my Rails 3.0.10/MRI app on Ubuntu 11.04 to JRuby 1.6.4 on Ubuntu 11.04. My goal is to get to a place where I just have to do the following to run the app under JRuby.
railsapp1> rbenv local jruby-1.6.4
railsapp1> rails server
And to get the app working under MRI,
railsapp1> rbenv local 1.9.2-p290
railsapp1> rails server
The first part of this problem was to resolve the gems. To make this process work without code changes I did the following in the Rails Gemfile
platforms :mri do
gem 'mysql2', '~>0.2.11'
end
platforms :jruby do
gem 'jruby-openssl'
gem 'activerecord-jdbcmysql-adapter'
end
Those gem statements were gotten using the brute-force method by creating dummy rails apps with different combinations of MRI/JRuby and SQLite/MySQL and then taking the gem statements from the generated Gemfiles for each combination.
That doesn't quite do it though. My config/database.yml file looks like this:
development:
adapter: mysql2
database: doodad
username: doodad
password: doodad
host: localhost
This config/database.yml file only works for the MRI version. For the JRuby version, the config/database.yml file looks like this:
development:
adapter: mysql
database: doodad
username: doodad
password: doodad
host: localhost
i.e. The only difference between the files is the name of the database adapter (mysql vs mysql2). Is there a way to tell the database.yml file or the system initializer to pick the adapter based on whether the Ruby environment is MRI or JRuby?