Rails vs. Grails vs. Helma: The JVM Web Framework Smackdown, Part 1

It's the ultimate JVM Web Framework Smackdown! Three will enter the cage. Only one will exit the victor. Will it be JRuby on Rails? Groovy on Grails? Or Helma?

Rails Scaffolding and Pagination

Once upon a time, Rails shipped with built-in features for dynamic scaffolding and pagination. These have been removed from the core framework in favor of separate plugins.

The removal of dynamic scaffolding is perhaps understandable—the dynamic scaffolding pages usually needed to be replaced anyway. Scaffolds are now created through the generate script. However, the loss of pagination is a little more disappointing. Although there are multiple pagination plugins available, the stock, generated controller and views do not use them. However, it is easy enough to integrate a plugin.

Rails’s non-dynamic generated scaffolding is an incredibly nice feature. It allows you to set up a useful data entry tool in virtually no time at all. However, Rails controllers for scaffolds assume that every action takes an ID field. You might have noticed the extraneous id=>0 in some of the code snippets. Without it, you are given an error.

ActiveRecord::RecordNotFound in UsersController#show
  Couldn't find User with ID=login

There are ways around this problem. The easiest is simply to use a different controller for those actions. You can also attempt to edit config/routes.rb. Passing a fake ID is probably the ugliest approach, but it works.

Integrating JRuby on Rails with Java

One of the benefits of JRuby is that, in addition to Java’s libraries, you have most of Ruby’s available as well. These include most libraries written in pure Ruby, and also those written in C that the JRuby team has ported over.

In the case of PenguinMusic, no Java library is required, but let’s pretend otherwise. How hard is it to integrate a Java library? Let’s replace the use of Ruby’s MD5 library with a call to a Java library. Java’s implementation is a little more complex, but a wrapper hides much of the detail. Here’s lib/utils/hash.rb:

require 'java'
  include_class 'java.security.MessageDigest'
  include_class('java.lang.String') {|package,name"J#{name}" }
  include_class('java.math.BigInteger') {|package,name"J#{name}" }

  module Utils
    class Hash
      def (Utils::Hash).md5sum(s)
        s = JString.new(s)
        m = MessageDigest.getInstance(JString.new "MD5")
        m.update(s.bytes, 0, s.length)
        JBigInteger.new(1, m.digest).toString(16)

Interacting with Java in JRuby is a little more complex than with the other languages, but not horribly so. The primary complication in the code above comes from the String class. Since JRuby does not use Java’s String class and is more strict about conversions, you must wrap any Strings passed to Java methods in a JString object.


Given the new hash function, it would be nice to test it. Testing is one of Rails’s real strengths. Rails generates testing classes and includes rake targets to run your tests automatically. Let’s hash a few different words to see if any problems crop up:

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  test "hash function" do
    assert_equal "fe01d67a002dfa0f3ac084298142eccd", Utils::Hash.md5sum("orange")
    assert_equal "72b302bf297a228a75730123efef7c41", Utils::Hash.md5sum("banana")
    assert_equal "c7a4476fc64b75ead800da9ea2b7d072", Utils::Hash.md5sum("cherry")
    assert_equal "9dee45a24efffc78483a02cfcfd83433", Utils::Hash.md5sum("pineapple")
    assert_equal "3f24e567591e9cbab2a7d2f1f748a1d4", Utils::Hash.md5sum("lemon")
    assert_equal "67c0ecaf5a1b782b11146e9fbe80f016", Utils::Hash.md5sum("lime")
    assert_equal "aa00faf97d042c13a59da4d27eb32358", Utils::Hash.md5sum("mango")
    assert_equal "027086dff18471311f7816dba7f92909", Utils::Hash.md5sum("artichoke")

When the tests run, the test for artichoke fails:

1) Failure:
test_hash_function(UserTest) [test/unit/user_test.rb:17]:
<"027086dff18471311f7816dba7f92909"> expected but was

Oops. The function is dropping the leading 0. A slight change fixes the problem:

      m.update(s.bytes, 0, s.length)
      hashVal = JBigInteger.new(1, m.digest).toString(16)
      format('%32.32s', hashVal.to_s).gsub /\s/, '0'

This really just scratches the surface of the testing tools Rails offers. Rails makes it so easy to get started, even giving you a few basic functional tests to begin with.

Is JRuby Worth It?

At this point, hardened Rails developers might well wonder if JRuby on Rails really offers any tangible benefits. If you do not need any of Java’s libraries, is it really worth the additional hassle and complexity?

There is a trade-off. If you choose JRuby as your implementation, you gain a little extra hassle, and you may run into problems that no one else has faced. You also give up continuations. On the other hand, you gain a superior threading model and better support for Unicode, though for the latter you need to use Java’s String class instead of Ruby’s. Deployment may arguably be a little simpler—using Warbler, you can deploy your JRoR application as a standard WAR file. You also, of course, gain access to the cornucopia of Java tools and libraries.

The Final Word on JRoR

Ruby on Rails has set the bar for Web development. The exciting thing about JRoR is that it feels no different from Rails development. At the same time it’s a little disappointing that JRoR is, well, no different than Rails development.

While Ola Bini and others have highlighted some ways that different Java components could be used, it would be nice to have a couple of extra features to help distinguish JRoR from Rails. Of course, the issue is that there is no JRoR team. There is the JRuby team, and the Rails team.

But in the end, JRoR works as well as advertised. For those who already have some expertise with Rails and wish to take advantage of Java libraries, JRoR is probably the best option.

The Good

  • Robust framework, with a rich set of Ruby libraries in addition to Java libraries
  • Easy learning curve for those who already know Ruby on Rails
  • Excellent tools for testing

The Bad

  • Views quickly become littered with code
  • Essentially a Ruby framework — does not leverage Java tools.

Check back for Part 2 where we tackle Grails!

Comments on "Rails vs. Grails vs. Helma: The JVM Web Framework Smackdown, Part 1"

My programmer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses. But he’s
tryiong none the less. I’ve been using WordPress on various websites for about a year and
am anxious about switching to another platform. I have heard excellent things about blogengine.net.
Is there a way I can transfer all my wordpress content into it?
Any help would be greatly appreciated!

It is necessary to maintain control of one’s thoughts while
performing almost any trading.

Also visit my blog forex brokers in cyprus (https://www.eventbrite.com/e/best-forex-brokers-tickets-18350646277)

Let us start with what the currency exchange rate is.

It is the pace of which one currency could be exchanged for another

Review my website http://www.panorama.it/magazine/tasse-risparmi-conti-correnti/

A lot more essential, you’ve to master what can cause rates to go along or up and regarding the foreign exchange marketplace.

Feel free to surf to my weblog; http://24h.net.au/lifestyle/meet-the-real-life-popeye-and-his-big-hands/

forex trading platforms [kcraftmc.com] is foreign exchange trading and it’s also the
biggest lively most liquid marketplace on the planet.

Admiring the dedication you put into your blog and detailed information you provide.
It’s awesome to come across a blog every once in a while
that isn’t the same unwanted rehashed information. Great read!
I’ve bookmarked your site and I’m including
your RSS feeds to my Google account.

They can be generally grouped into two sort of strategies are profit maximizing strategies decreasing strategies.

Here is my web-site: forex trading basics (data.adliberum.com)

InstaForex providers are of the good attention for over 2
000 000 forex brokers in pakistan (http://otobe4.tea-nifty.com/) traders all around the planet nowadays.

I’m really enjoying the theme/design of your weblog. Do you ever run into any
internet browser compatibility problems? A handful of my blog readers have complained
about my site not operating correctly in Explorer but looks great in Chrome.
Do you have any ideas to help fix this issue?

Trading – so that you can consider tiny gains, new dealers may place extremely limited requests.

Feel free to surf to my web-site forex brokers in cyprus

I am a Chartered Accountant, stock and forex market broker, business owner and home investor.

Feel free to visit my webpage :: http://pipeclass.com/index.php/en/guestbook-libro-visitas

I’ve chosen to wander along the less- sailed road and ventured
to the sphere of trading the a lot longer-term graphs.

Here is my web site: forex brokers in nigeria (Loretta)

Because period of time the persons at FxKeys and also you have coached me how exactly to have a life trading Forex.

Visit my blog :: http://www.linux-mag.com/id/7190/

Instead of seeking for weeks while risking your hard
earned cash, to crack the forex brokers in kenya (http://prezent-tour.ru/index.php?option=com_k2&view=item&id=101:navostok&con=996/rss/news/index.xml) rule, take a moment and feel.

The key elements forex brokers in india-stock trading is usually to not be
unable to follow rigid trading principles and
having self discipline.

For key providers, how big the party and the waiting time are inversely

my blog … health insurance australia

Insurance providers offering class health insurance quotes-insurance are forbidden legally from denying coverage based on ones own recent health or

Great, thanks for sharing this article.Really thank you! Keep writing.

One of our guests recently advised the following website.

Awsome blog! I am loving it!! Will be back later to read some more. I am taking your feeds also.

Say, you got a nice blog article.Much thanks again. Fantastic.

Thank you for great information I was on the lookout for this info for my mission.

This is one awesome post.Really looking forward to read more. Much obliged.

Check beneath, are some totally unrelated websites to ours, having said that, they may be most trustworthy sources that we use.

This is one awesome blog article. Fantastic.

Although websites we backlink to below are considerably not associated to ours, we really feel they may be truly really worth a go as a result of, so have a look.

Just beneath, are various entirely not connected sites to ours, on the other hand, they’re surely worth going over.

Below you will come across the link to some web sites that we consider you need to visit.

Fantastic blog article.Really thank you! Fantastic.

I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that’s at the other blogs. Appreciate your sharing this best doc.

Looking forward to reading more. Great blog.Really thank you! Really Great.

Really informative blog article.Thanks Again. Will read on…

One of our guests just lately encouraged the following website.

wow, awesome article. Really Cool.

“obviously like your web site but you need to check the spelling on quite a few of your posts. Many of them are rife with spelling problems and I in finding it very bothersome to tell the truth on the other hand I will definitely come back again.”

One of our visitors lately suggested the following website.

Sites of interest we’ve a link to.

The data mentioned within the article are a few of the ideal readily available.

Leave a Reply