Miles to go …

December 21, 2007

JRuby 1.0.3 + Rails 2.0 Hello World – Additional Steps Required

Filed under: web2.0 — arungupta @ 11:19 am


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:

  1. Unzip JRuby 1.0.3.
    1. Make sure to set JAVA_HOME and JRUBY_HOME.
    2. Also include JAVA_HOME/bin and JRUBY_HOME/bin in PATH for convenience.
  2. 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

  3. Create a simple app using the following steps
    1. Create a template app as:

      jruby -S rails --database mysql hello or jruby -S rails -d mysql hello

      It’s important to specify --database mysql otherwise Rails 2.0 uses sqlite3 as the default database.

    2. Add a Controller and View as:

      cd hello
      jruby script/generate controller say hello
    3. Edit the controller as:

      vi app/controllers/say_controller.rb

      and add the following variable in “hello” helper method:

      @hello_string = ""

    4. Edit the View as:

      vi app/views/say/hello.html.erb

      and add the following as last line:

      <%= @hello_string %>

      Notice, the view extension is .html.erb instead of .rhtml.

  4. Download, Install and Configure MySQL (additional step for Rails 2.0)
    1. Mac OS comes pre-installed with MySQL in /usr/local/mysql directory. Start the server as:

      sudo ./bin/mysqld_safe

      Alternatively, you can download and install MySQL Universal server (only .dmg format, not tar.gz format as specified here).

    2. Create a database as:

      sudo ./bin/mysqladmin create hello_development

  5. Start the WEBrick server (in hello directory) as:

    jruby script/server

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:

JRuby 1.0.3 + Rails 2.0 Hello World

Want to try this application on GlassFish v3 gem (download or build your own – now down to 2.4 MB) ?

Technorati: ruby jruby rails mysql glassfish v3 gem

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1
  2. JRuby on Rails, NetBeans 6 and GlassFish V2 – Simplified Steps
  3. TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
  4. Database-enabled Hello World RoR app
  5. TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows

4 Comments »

  1. Actually the extension should be .html.erb

    Comment by Alex MacCaw — December 22, 2007 @ 1:04 am

  2. You are right, now fixed!

    Comment by Arun Gupta — December 22, 2007 @ 2:40 pm

  3. Merry Christmas to you and your friends,your family.

    Comment by michael wang — December 24, 2007 @ 7:10 pm

  4. [Trackback] &quot;sakila&quot; is the sample database shipped with MySQL (pronounced as my ess-kew-ell). In the context of Sun Microsystems announcing the agreement to acquire MySQL, I’d like to dedicate this entry to show how this sample database can be exposed a…

    Comment by Arun Gupta's Blog — January 24, 2008 @ 4:46 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress