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="http://en.oreilly.com/rails2009/public/schedule/detail/7787">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:


style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
<% 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 href="http://blog.nicksieger.com/jruby-railsconf-2009.pdf">here.
Learn about other related talks href="http://blog.arungupta.me/2009/04/27/glassfish-and-netbeans-at-rails-conf-2009.aspx">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="http://blogs.sun.com/arungupta/tags/totd">here.




Technorati: conf
railsconf
lasvegas
tutorial
jruby
ruby href="http://technorati.com/tags/rubyonrails">rubyonrails

Related Topics >>