120 seconds guide to JRuby on Rails
So, you have that new and shiny JRuby 1.1 and would like to try it out with rails. Here’s a quickest guide to do so! The guide assumes that you want to use MySQL as the database, and it has already been installed.
First, install the following gems:
- mongrel - simple but powerful web server.
- activerecord-jdbcmysql-adapter - all you need for activerecord on JRuby to talk to MySQL.
- rails - well, the Ruby on Rails proper.
The command line:
1: jruby -S gem install mongrel activerecord-jdbcmysql-adapter rails
Create a sample rails application with MySQL backend:
1: jruby -S rails myapp -d mysql
Enter the newly-created “myapp” directory, then modify the config/database.yml. First and foremost, you need to adjust the adapter name, and instead of ‘mysql’ you should specify ‘jdbcmysql’. You might also want to delete the lines starting with “socket:”.
Here’s a simple example for the development environment:
1: development:
2: adapter: jdbcmysql
3: encoding: utf8
4: database: myapp_development
5: username: root
6: password:
Now, it’s time to create our database:
1: jruby -S rake db:create:all
The next step is to create some minimal scaffolding so that you could actually play with some dynamic functionality and database access:
1: jruby script/generate scaffold post title:string body:text published:boolean
We need to update the database after that:
1: jruby -S rake db:migrate
And we’re basically done here, just start rails via:
1: jruby script/server
and point your browser to the:
Enjoy!
April 13th, 2008 at 11:40 pm
is there a way to run mongrel cluster?
April 15th, 2008 at 9:55 am
Khell, yes there is. Take a look here: http://ola-bini.blogspot.com/2007/05/announcing-mongreljcluster.html
Also, there was a bug in early days of JRuby 1.1RC, but it was fixed for JRuby 1.1: http://jira.codehaus.org/browse/JRUBY-1705
April 22nd, 2008 at 8:53 pm
Hi,
Do you (or anyone) know the “official” list of things to install when working with Jruby, rails and mysql?
I’ve seen reference to needing to install mysql-connector into the jruby install directory, or activerecord-jdbc-adapter, or just the activerecord-jdbcmysql-adapter you mentioned above.
thanks!
April 22nd, 2008 at 9:12 pm
Jay, the list of gems, provided in the blog entry, is what’s needed, nothing else. Well, activerecord-jdbcmysql-adapter gem has dependencies on other gems and they will be installed automatically.
July 10th, 2008 at 11:03 pm
Good!!!
I have developed with the NetBeans 6.1 and liked so much.