Skip to main content

TOTD #81: How to configure "database.yml" to be used with both JRuby and MRI ?

Posted by arungupta on May 4, 2009 at 9:58 AM PDT

In href="">JRuby-on-Rails
tutorial at Rails
Conf 2009
, Nick
shared a nice little tip on how to configure
"database.yml" to be usable with both JRuby and MRI:

style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
<% jdbc = defined?(JRUBY_VERSION) ? 'jdbc' : ''


  adapter: <%= jdbc %>mysql

  encoding: utf8

  reconnect: false

  database: myapp_development

  pool: 5

  username: root


  socket: /tmp/mysql.sock

# ...

"JRUBY_VERSION" is defined only if your using JRuby and so the right
database adapter is picked up accordingly.

The complete slides for the tutorial are available href="">here.
Learn about other related talks href="">here.

Please leave suggestions on other TOTD ( style="font-weight: bold;">Tip style="font-weight: bold;">Of style="font-weight: bold;">The style="font-weight: bold;">Day) that
you'd like to see.
An archive of all the tips is available href="">here.

Technorati: conf
ruby href="">rubyonrails

Related Topics >>