Showing posts with label RoR. Show all posts
Showing posts with label RoR. Show all posts

Sunday, September 12, 2010

JRuby and Rails 3

Rails 3.0 has been released. I know a number of you are excited about all of the possibilities. Along with the release of Rails is a new point release of JRuby.  So the big question is how do you use them together.

The default Rails environment uses SQLite as the database. Let me show you how to get started.
Riding on JRuby on Rails

  1. Start by downloading JRuby, and install it.
  2. Once it is installed you will want to install jruby-openssl.
    jruby -S gem install jruby-openssl
  3. Next lets install the SQLite database gems.
    jruby -S gem install jdbc-sqlite3 activerecord-jdbc-adapter \
    activerecord-jdbcsqlite3-adapter

  4. Once we have installed the gems for SQLite, we can install Rails.
    jruby -S gem install rails mongrel warbler
  5. Now that Rails is installed, we can create our example application. This will create our application.
    jruby -S rails new blog
  6. Next we replace the following line in the Gemfile

    gem 'sqlite3-ruby', :require => 'sqlite3'

    with the following:

    if defined?(JRUBY_VERSION)
    gem 'jdbc-sqlite3'
    gem 'activerecord-jdbc-adapter'
    gem 'activerecord-jdbcsqlite3-adapter'
    gem 'jruby-openssl'
    gem 'jruby-rack'
    gem 'warbler'
    else
    gem 'sqlite3-ruby', :require => 'sqlite3'
    end

    This allows us to run the application in JRuby, or Ruby.
  7. Next we need to modify the config/database.yml file.

    # SQLite version 3.x
    # gem install sqlite3-ruby (not necessary on OS X Leopard)
    development:
    adapter: jdbcsqlite3
    database: db/development.sqlite3
    pool: 5
    timeout: 5000

    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
    adapter: jdbcsqlite3
    database: db/test.sqlite3
    pool: 5
    timeout: 5000

    production:
    adapter: jdbcsqlite3
    database: db/production.sqlite3
    pool: 5
    timeout: 5000

  8. Next we need to migrate the database.
    jruby -S rake db:migrate
  9. Finally we can start our new Rails 3 application.
    jruby -S rails server
That's it. You are riding on Rails in 9 steps.

References:


Enhanced by Zemanta

Thursday, February 25, 2010

Book Review - NetBeans Ruby and Rails IDE with JRuby


I decided to write a quick review on the NetBeans Ruby and Rails IDE with JRuby book from Apress. The book is focused on NetBeans 6.5 and JRuby development. This is not a limitation on the book however. The book is really an introduction to how to use NetBeans to do Ruby development. The latest version of NetBeans (6.8) has a number of additional features (enhancements) over the version detailed in this book. Perhaps the authors can do an up-to-date version of the book to cover the latest enhancements. If not, perhaps I will consider taking up the mantle.

I really loved the book. I would give it 4/5 stars which if you have read my reviews is a brutal rating to get.

I performed a baseline install of NetBeans 6.5 including the plugins required for doing JRuby/Ruby development as noted in the book. The book follows along perfectly with the installer and IDE. I guess you could call this book the reference to the IDE for JRuby/Ruby development.

The first chapter details the installation and configuration of the IDE. The explanation is spot on, but NetBeans is also really to install and configure.

The second chapter covers your basic "Hello World" from both a basic JRuby project and from JRuby on Rails (JRoR).

The third chapter covers configuration of JRuby using the NetBeans gem manager, setting up servers, and configuring databases for use with the development environment. The section on gems with native extensions, and replacements is very helpful.

Chapters four and five cover Ruby and Rails projects in more detail. It demonstrates a number of the capabilities that the IDE.  I really like the Rails Console and example of how to use it.

Chapter six covers editing files and the capabilities that the IDE provides including code completion. This was the first real mainstream IDE to provide JRuby/Ruby code completion. It does it beautifully.

Chapter seven covers debugging and testing. The authors do a great job of explaining why NetBeans should be your choice of IDE for doing Ruby development.

JRuby itself is the topic of chapter eight. There is an example of how to use JRuby in Java projects. This is really cool. However, it should be noted that you need to make some changes for it to work on JSE5. This is noted on Page 136, but the code needs a slight modification to use JRubyScriptEngineManager instead of ScriptEngineManager.

Chapter nine covers Ruby on Rails (RoR) deployments using warbler. I have found warbler to be a great  tool and use it extensively to deploy applications to GlassFish v 2.x.

Chapter ten is all about the IDE. It shows the user a number of customizations available to make NetBeans customized to your style.  This is no small accomplishment. The NetBeans team have made a really great IDE and made it extremely flexible. This flexibility did not sacrifice simplicity. Eclipse is flexible too, but a a severe penalty to ease.

In summary, if you are thinking of trying JRuby, or Ruby development, and you want to give NetBeans a try, this is the book to buy 4/5 stars.

Errata

There is not much to report. My only real gripe is that the Mac short-cut keys are incorrect in a number of places. However, you will figure it out immediately. If it says <cmd> and it does not work... try <ctrl>.

(Page 43)  Item #2 refers to a diagram which is not correct. The diagram which it refers to is not in the book.

(Page 133) The diagram JVM arguments are incorrect. The correct argument is listed under the input box as part of the inline help.

Popular Posts