JRuby 1.0.3 was recently released and so was Rails 2.0. I decided to try JRuby 1.0.3 + Rails 2.0 and realized that a few additional steps (because of Rails 2.0) are required to get a trivial Hello World applcation up and running. Here are the steps:
- Unzip JRuby 1.0.3.
- Make sure to set JAVA_HOME and JRUBY_HOME.
- Also include JAVA_HOME/bin and JRUBY_HOME/bin in PATH for convenience.
- Install Rails 2.0 as shown below:
~/samples/jruby arungupta$ jruby -S gem install rails --include-dependencies --no-ri --no-rdoc
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-2.0.2
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
Successfully installed actionpack-2.0.2
Successfully installed actionmailer-2.0.2
Successfully installed activeresource-2.0.2
- Create a simple app using the following steps
- Create a template app as:
jruby -S rails --database mysql helloor
jruby -S rails -d mysql hello
It’s important to specify
--database mysqlotherwise Rails 2.0 uses sqlite3 as the default database.
- Add a Controller and View as:
jruby script/generate controller say hello
- Edit the controller as:
and add the following variable in “hello” helper method:
@hello_string = ""
- Edit the View as:
and add the following as last line:
<%= @hello_string %>
Notice, the view extension is
- Download, Install and Configure MySQL (additional step for Rails 2.0)
- Mac OS comes pre-installed with MySQL in /usr/local/mysql directory. Start the server as:
- Create a database as:
sudo ./bin/mysqladmin create hello_development
- Start the WEBrick server (in hello directory) as:
That’s it, now your trivial
Hello World application is deployed using JRuby 1.0.3 + Rails 2.0 and displays the output in a browser window as:
- TOTD #24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1
- JRuby on Rails, NetBeans 6 and GlassFish V2 – Simplified Steps
- TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
- Database-enabled Hello World RoR app
- TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows