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

Guest Author

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' : '' %>
  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 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

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.