X

JRuby 1.0.3 + Rails 2.0 Hello World - Additional Steps Required

Guest Author


JRuby 1.0.3
was href="http://docs.codehaus.org/display/JRUBY/2007/12/15/JRuby+1.0.3+Released">recently
released and so was href="http://weblog.rubyonrails.org/2007/12/7/rails-2-0-it-s-done">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 href="http://dist.codehaus.org/jruby/jruby-bin-1.0.3.zip">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 orjruby -S rails -d mysql hello


      It's important to specify --database mysql
      otherwise Rails 2.0 uses href="http://weblog.rubyonrails.org/2007/12/17/rails-2-0-2-some-new-defaults-and-a-few-fixes">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 href="http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.45-osx10.4-i686.dmg/from/pick">MySQL
      Universal server (only .dmg format, not tar.gz format as
      specified href="http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html">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:



alt="JRuby 1.0.3 + Rails 2.0 Hello World"
src="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/dce2c9c4755b9d7c1f9c42c912cf7523/jruby103_rails2_helloworld.png">




Want to try this application on href="http://blogs.sun.com/arungupta/entry/announcing_glassfish_gem_for_rails">GlassFish
v3 gem ( href="http://download.java.net/maven/glassfish/com/sun/enterprise/glassfish/glassfish-gem/10.0-SNAPSHOT/glassfish-gem-10.0-SNAPSHOT.gem">download
or href="http://blogs.sun.com/arungupta/entry/totd_18_how_to_build1">build
your own - now down to 2.4 MB) ?



Technorati: ruby
jruby href="http://technorati.com/tag/rails">rails href="http://technorati.com/tag/mysql">mysql href="http://technorati.com/tag/glassfish">glassfish
v3
gem

Join the discussion

Comments ( 4 )
  • Alex MacCaw Saturday, December 22, 2007

    Actually the extension should be .html.erb


  • Arun Gupta Saturday, December 22, 2007

    You are right, now fixed!


  • michael wang Monday, December 24, 2007

    Merry Christmas to you and your friends,your family.


  • Arun Gupta's Blog Thursday, January 24, 2008
    [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...
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.