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


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

<% jdbc = defined?(JRUBY_VERSION) ? 'jdbc' : '' %>
development:
  adapter: <%= jdbc %>mysql
  encoding: utf8
  reconnect: false
  database: myapp_development
  pool: 5
  username: root
  password:
  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 here. Learn about other related talks here.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. An archive of all the tips is available here.

Technorati: conf railsconf lasvegas tutorial jruby ruby rubyonrails

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments
  • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.