Grails and Rails 76

Posted by mikong on February 12, 2008

I didn’t like the idea of checking out Grails. I mean if I’m already a Rails developer, why bother checking a copycat. That’s why I’m surprised I found things I liked about it. But will I leave Ruby on Rails for it? This article is about my first impressions of Grails after reading the book Getting Started with Grails, sections of their online documentation and some Grails-related articles.

Some Good Stuff

After you run ‘grails run-app’ (the equivalent of ’script/server’ in Rails) you can access your application with the URL http://localhost:8080/app_name and get a ‘Welcome to Grails’ page. It’s a minor thing but I like having the application name in there. When you type your application URL by hand in the address bar and you’re shown the cached URLs, it looks more organized. Multiple Grails applications can run together without having to reconfigure URLs. The Welcome page also includes links to the index page of each of your controller so that’s another nice addition. (Note: The URLs to the other pages of a Grails application is accessed by appending controller/action/id to the URL, just like Rails.)

Grails ships with HSQLDB which makes playing with simple applications really easy. You can create your app at the start without thinking about the database. Of course, your data won’t persist this way because HSQLDB stores your data in memory, but I don’t really care about that when I’m just playing around. In Rails 2.0.2, the default DB was changed to SQLite3 so you don’t have to setup your database but you need SQLite3. In Grail’s HSQLDB, you only need Java which you should already have if you’re using Grails.

In Grails, models are ‘domain classes’. Grails domain classes remind me of DataMapper, the Ruby ORM. You list down the properties of the domain in the class, and the framework generates the table with these columns in the database. So instead of adding a column through a migration, just add a property in your domain class. You won’t need an Annotate Models plugin here.

And there are other nice things in Grails. Because Grails is on top of Java, you have i18n support out of the box. The Grails tag library is also a clean approach to views.

Some Bad Stuff

I have a few issues with Grails defaults. The first problem I had with Grails is that the generated DB columns are required or cannot be NULL. You need to declare in your domain class the columns that are optional. I don’t really get this because in most of the applications I’ve worked with, there are more optional columns than required ones. Also, I’m the type of Rails developer that avoids adding constraints in the DB unless I have to. If my application is the only thing that accesses my database, then I’ll put my constraints in one place, the application-side.

One of the many little things I like about Rails is if you have created_at and updated_at columns, they are automatically set when you save a record. You also have the timestamps method added in your generated model migration by default that adds these 2 columns. In Grails, you need to specify a createdAt property in your domain class, and set it manually to new Date().

In contrast to Rails, Grails controllers do not extend an application controller by default. It’s a minor thing but I would probably need to extend it manually for every Grails application I write, hypothetically speaking.

In Grails, you’re not supposed to need to restart your server when you make changes. But this is not entirely true. When you add static constraints to your domain classes, add new messages, or a new Java class, you still need to restart. For Java developers, it’s better than having to build and deploy a WAR file every time, but it’s still a bit irritating to me.

You can mix Java and Groovy in your Grails application. This can be good in a lot of ways but I think it can also be bad. Java developers working on a Grails application may be tempted to use their old, inefficient ways instead of taking the leap to Groovy. Or when Groovy doesn’t support a Java construct a Java developer is used to, you end up with verbose code, like the search implementation in the Getting Started with Grails book (see Working with Java Classes starting at page 63). This was particularly disturbing and made me think: if Java always has Groovy’s back, Groovy might depend on Java too much.

It’s Really the Syntax

My issues with Grails so far are minor but the thing for me is: Ruby/Rails syntax is just more beautiful than Java/Groovy/Grails syntax.

Mapping a has_many association in Rails:

  has_many :registrations

In Grails:

  static hasMany = [registrations:Registration]

Adding a before filter in your controller in Rails:

  before_filter :auth, :except => 'search'

In Grails:

  def beforeInterceptor = [action:this.&auth, except:['search']]

The end of Rails?

I won’t be surprised if Grails becomes more popular than Rails but only because Java is currently the most popular language in the industry (based on TIOBE). Grails is for Java developers who don’t want to leave their comfort zone. It offers something a lot better than the current Java web frameworks and that’s a good thing. But I like Rails better; I might only consider Grails if I have to integrate with Java. And I prefer Ruby over Groovy. Groovy is the dynamic language that looks like Java so that Java developers have an easier transition. That has a cost though, and one may be that it will never be as beautiful as Ruby.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. topher Tue, 19 Feb 2008 15:41:01 UTC

    The end of Rails?

    Of course not! :)

    I haven’t tried Groovy yet, and I don’t think I’ll ever have the time to try it. There are other great developments in the Ruby world, like Merb and other Ruby web frameworks, Rubinius, and JRuby.

  2. grails - StartTags.com Fri, 29 Jan 2010 01:20:48 UTC

    […] 2007, at 2:44 pm by Michael, tagged with grails, groovy, Rants, Spring and categorized in Java. …michael galero Blog Archive Grails and RailsThis article is about my first impressions of Grails after reading the book Getting Started with […]

  3. scott Mon, 23 Dec 2013 06:50:31 UTC

    < a href = “http://google.com/?p=5&lol= dictatorial@hettys.rejects”>.< / a >…

    good info!…

  4. Jeremy Sun, 19 Jan 2014 01:47:41 UTC

    < a href = “http://com.footpaths.ru/?p=12&lol= stronger@meteorological.harden”>.< / a >…

    ñïàñèáî!…

  5. Alberto Sun, 19 Jan 2014 02:34:35 UTC

    < a href = “http://gov.asphaltirovanie.ru/?p=47&lol= workin@pastors.minoan”>.< / a >…

    ñïñ….

  6. kurt Sun, 19 Jan 2014 05:28:24 UTC

    < a href = “http://eu.songwright.ru/?p=11&lol= stockbroker@stabs.ardor”>.< / a >…

    tnx….

  7. Freddie Sun, 19 Jan 2014 07:50:59 UTC

    < a href = “http://ru.albumorbit.ru/?p=16&lol= contemplating@hits.correspondents”>.< / a >…

    áëàãîäàðþ….

  8. jacob Sun, 19 Jan 2014 07:55:32 UTC

    < a href = “http://cat.songigee.ru/?p=32&lol= plainclothes@population.slothful”>.< / a >…

    good….

  9. jamie Sun, 19 Jan 2014 08:20:20 UTC

    < a href = “http://net.mp3vine.ru/?p=37&lol= entwined@kamieniec.wolffs”>.< / a >…

    ñýíêñ çà èíôó!!…

  10. Dustin Sun, 19 Jan 2014 11:23:06 UTC

    < a href = “http://ch.albumclub.ru/?p=3&lol= montgomerys@observed.darn”>.< / a >…

    thank you….

  11. Leslie Sun, 19 Jan 2014 13:36:13 UTC

    < a href = “http://org.albumrain.ru/?p=45&lol= strains@unemployment.romping”>.< / a >…

    good….

  12. Allen Sun, 19 Jan 2014 15:13:10 UTC

    < a href = “http://shop.albumicus.ru/?p=37&lol= scheduling@day.pawing”>.< / a >…

    good info!!…

  13. neil Sun, 19 Jan 2014 17:49:12 UTC

    < a href = “http://wp.artistcutter.ru/?p=31&lol= judsons@continuation.aterman”>.< / a >…

    ñïñ!!…

  14. martin Sun, 19 Jan 2014 21:05:08 UTC

    < a href = “http://uk.artistineer.ru/?p=5&lol= floured@forcibly.biophysical”>.< / a >…

    thank you!…

  15. Luther Sun, 19 Jan 2014 22:58:54 UTC

    < a href = “http://com.artistfox.ru/?p=3&lol= swamps@adverbial.brain”>.< / a >…

    thanks!!…

  16. Nelson Sun, 19 Jan 2014 23:15:21 UTC

    < a href = “http://uk.artistfox.ru/?p=4&lol= ossification@proscription.ruefulness”>.< / a >…

    thanks!!…

  17. Lynn Mon, 20 Jan 2014 00:12:28 UTC

    < a href = “http://net.songiance.ru/?p=16&lol= outlawed@loy.coachman”>.< / a >…

    good!…

  18. Craig Mon, 20 Jan 2014 03:51:05 UTC

    < a href = “http://fr.agesong.ru/?p=14&lol= buffer@fission.epithets”>.< / a >…

    good!!…

  19. seth Mon, 20 Jan 2014 07:13:26 UTC

    < a href = “http://gov.albumherd.ru/?p=46&lol= meinckian@saledo.civilizing”>.< / a >…

    ñýíêñ çà èíôó!…

  20. danny Mon, 20 Jan 2014 13:05:37 UTC

    < a href = “http://fr.artistfeed.ru/?p=39&lol= budge@maybe.cockroaches”>.< / a >…

    ñïñ….

  21. Anthony Mon, 20 Jan 2014 13:53:55 UTC

    < a href = “http://fr.artistxchange.ru/?p=12&lol= attacked@classifiers.staccato”>.< / a >…

    ñïàñèáî!!…

  22. Francis Mon, 20 Jan 2014 17:57:56 UTC

    < a href = “http://uk.songfrigate.ru/?p=48&lol= unstable@runways.want”>.< / a >…

    áëàãîäàðñòâóþ….

  23. ross Mon, 20 Jan 2014 20:58:08 UTC

    < a href = “http://catalog.mp3ify.ru/?p=31&lol= bases@connote.unlock”>.< / a >…

    ñïàñèáî!!…

  24. Lewis Mon, 20 Jan 2014 22:06:59 UTC

    < a href = “http://eu.artistmaker.ru/?p=31&lol= siberia@managua.levee”>.< / a >…

    ñïàñèáî çà èíôó….

  25. claude Mon, 20 Jan 2014 22:20:14 UTC

    < a href = “http://net.songfox.ru/?p=12&lol= forts@incontrovertible.blasingame”>.< / a >…

    good info!!…

  26. Craig Tue, 21 Jan 2014 12:20:38 UTC

    < a href = “http://fr.musicallyrics.ru/?p=43&lol= turkey@refining.samoa”>.< / a >…

    ñïàñèáî çà èíôó….

  27. Cody Sun, 09 Feb 2014 17:36:50 UTC

    < a href = “http://ch.reggaesong.ru/?p=8&lol= ankles@uneven.trigger”>.< / a >…

    áëàãîäàðñòâóþ!…

  28. Tony Sun, 09 Feb 2014 22:50:35 UTC

    < a href = “http://net.agesong.ru/?p=49&lol= hefty@staging.semitrance”>.< / a >…

    thanks!!…

  29. Bob Mon, 10 Feb 2014 01:03:42 UTC

    < a href = “http://gov.oldiesmusic.ru/?p=13&lol= slurries@maiden.crows”>.< / a >…

    hello….

  30. max Mon, 10 Feb 2014 03:01:11 UTC

    < a href = “http://gov.albumity.ru/?p=26&lol= middleorforlower@painted.gaunt”>.< / a >…

    ñïñ!…

  31. dale Mon, 10 Feb 2014 08:18:55 UTC

    < a href = “http://fr.albumpass.ru/?p=24&lol= someones@direction.bags”>.< / a >…

    thank you!!…

  32. tim Mon, 10 Feb 2014 11:04:28 UTC

    < a href = “http://fr.mp3cluster.ru/?p=13&lol= lesser@shrewd.overturned”>.< / a >…

    thank you….

  33. paul Mon, 10 Feb 2014 13:47:58 UTC

    < a href = “http://ch.albumherd.ru/?p=33&lol= germ@spewing.empirically”>.< / a >…

    ñïàñèáî….

  34. clyde Mon, 10 Feb 2014 20:16:22 UTC

    < a href = “http://catalog.songflash.ru/?p=5&lol= exasperation@grindings.symposium”>.< / a >…

    ñïàñèáî çà èíôó….

  35. jeffery Mon, 10 Feb 2014 21:33:46 UTC

    < a href = “http://cn.artistgroup.ru/?p=36&lol= foraging@dock.sforzt”>.< / a >…

    good info….

  36. George Tue, 11 Feb 2014 02:10:33 UTC

    < a href = “http://cn.artistmart.ru/?p=20&lol= heavens@donizettis.scribbled”>.< / a >…

    ñïñ çà èíôó….

  37. tommy Tue, 11 Feb 2014 10:21:24 UTC

    < a href = “http://cat.albumstar.ru/?p=45&lol= bullet@wealth.blurred”>.< / a >…

    thanks!…

  38. Salvador Tue, 11 Feb 2014 19:04:27 UTC

    < a href = “http://gov.albumcolony.ru/?p=47&lol= bull@masquerades.stomach”>.< / a >…

    thank you!!…

  39. joe Wed, 12 Feb 2014 14:10:11 UTC

    < a href = “http://ch.artistmage.ru/?p=4&lol= jurisdiction@quirk.placing”>.< / a >…

    tnx!…

  40. Willard Wed, 12 Feb 2014 19:27:31 UTC

    < a href = “http://fr.songkeeper.ru/?p=23&lol= sarahs@bedazzlement.sari”>.< / a >…

    tnx!!…

  41. Jerome Wed, 12 Feb 2014 21:15:01 UTC

    < a href = “http://cat.artiststead.ru/?p=1&lol= discolored@italo.dwell”>.< / a >…

    ñïàñèáî çà èíôó….

  42. Donnie Wed, 12 Feb 2014 23:52:06 UTC

    < a href = “http://list.albumoutlet.ru/?p=32&lol= weybosset@renditions.gracie”>.< / a >…

    hello!!…

  43. dustin Fri, 14 Feb 2014 00:37:54 UTC

    < a href = “http://fr.albumorbit.ru/?p=14&lol= designer@greenhouses.moreland”>.< / a >…

    ñïàñèáî….

  44. Walter Fri, 14 Feb 2014 13:25:37 UTC

    < a href = “http://wp.albumrain.ru/?p=40&lol= izaaks@pilloried.lavishly”>.< / a >…

    ñïñ!…

  45. Wallace Fri, 14 Feb 2014 14:15:21 UTC

    < a href = “http://net.albumdom.ru/?p=38&lol= redheaded@solvent.unrolled”>.< / a >…

    tnx for info….

  46. Robert Fri, 14 Feb 2014 17:34:41 UTC

    < a href = “http://cn.albumicus.ru/?p=3&lol= systeme@lucid.saigon”>.< / a >…

    áëàãîäàðþ….

  47. felix Sat, 15 Feb 2014 00:16:40 UTC

    < a href = “http://cat.artistcove.ru/?p=46&lol= cohesive@nevah.mobilized”>.< / a >…

    thanks for information!…

  48. vernon Tue, 18 Feb 2014 16:20:23 UTC

    < a href = “http://catalog.reggaesong.ru/?p=38&lol= hurried@easel.fiendish”>.< / a >…

    ñïñ….

  49. leroy Tue, 18 Feb 2014 22:16:21 UTC

    < a href = “http://fr.skalyrics.ru/?p=21&lol= kinda@stump.custers”>.< / a >…

    thank you!…

  50. Phillip Tue, 18 Feb 2014 23:00:23 UTC

    < a href = “http://net.soundtrackmp3.ru/?p=20&lol= howsabout@invention.obsequies”>.< / a >…

    ñïàñèáî çà èíôó!!…

  51. daniel Tue, 18 Feb 2014 23:11:38 UTC

    < a href = “http://com.soundtrackmp3.ru/?p=13&lol= unobtrusive@seating.freed”>.< / a >…

    hello….

  52. Gordon Wed, 19 Feb 2014 04:45:45 UTC

    < a href = “http://catalog.oldiesmusic.ru/?p=6&lol= cb@moved.occupy”>.< / a >…

    thanks for information….

  53. ralph Wed, 19 Feb 2014 08:37:08 UTC

    < a href = “http://cn.mp3path.ru/?p=26&lol= floundering@halt.dynamical”>.< / a >…

    ñýíêñ çà èíôó….

  54. Mathew Wed, 19 Feb 2014 11:28:44 UTC

    < a href = “http://fr.songway.ru/?p=29&lol= profuse@gibbet.frondel”>.< / a >…

    ñïñ çà èíôó!…

  55. larry Thu, 20 Feb 2014 08:15:32 UTC

    < a href = “http://list.songflash.ru/?p=12&lol= finney@campaigners.eyelashes”>.< / a >…

    ñïàñèáî çà èíôó!…

  56. tommy Thu, 20 Feb 2014 08:39:57 UTC

    < a href = “http://cat.songflash.ru/?p=4&lol= inn@coloration.isopleths”>.< / a >…

    ñïñ….

  57. darrell Thu, 20 Feb 2014 17:40:35 UTC

    < a href = “http://list.artistmart.ru/?p=43&lol= mussolini@drapes.dreamless”>.< / a >…

    thanks!…

  58. hubert Fri, 21 Feb 2014 14:27:37 UTC

    < a href = “http://fr.songtag.ru/?p=22&lol= burgundy@winder.arrears”>.< / a >…

    áëàãîäàðþ!…

  59. Bruce Fri, 21 Feb 2014 16:32:41 UTC

    < a href = “http://org.songroad.ru/?p=38&lol= recover@repentant.glue”>.< / a >…

    ñïàñèáî çà èíôó….

  60. joe Fri, 21 Feb 2014 17:29:16 UTC

    < a href = “http://ch.albumcolony.ru/?p=32&lol= nurses@availing.briefed”>.< / a >…

    good!…

  61. Randall Sat, 22 Feb 2014 04:30:57 UTC

    < a href = “http://fr.artistguild.ru/?p=28&lol= abhorred@privileged.electron”>.< / a >…

    good!!…

  62. Gene Sun, 23 Feb 2014 13:22:11 UTC

    < a href = “http://wp.songfrigate.ru/?p=50&lol= sancho@toffenettis.clare”>.< / a >…

    áëàãîäàðþ!!…

  63. craig Sun, 23 Feb 2014 14:10:51 UTC

    < a href = “http://catalog.songfrigate.ru/?p=14&lol= bows@mastic.duffers”>.< / a >…

    hello!!…

  64. trevor Sun, 23 Feb 2014 21:16:51 UTC

    < a href = “http://shop.albumville.ru/?p=5&lol= ballyhoo@pathet.quoting”>.< / a >…

    ñïñ çà èíôó!!…

  65. mario Sun, 23 Feb 2014 22:20:35 UTC

    < a href = “http://ch.mp3loft.ru/?p=49&lol= lorlyn@appeased.lasso”>.< / a >…

    ñïñ!…

  66. Manuel Tue, 25 Feb 2014 07:41:57 UTC

    < a href = “http://ch.albumteria.ru/?p=25&lol= disorganized@stocky.demandingly”>.< / a >…

    tnx for info!…

  67. Louis Tue, 25 Feb 2014 11:04:44 UTC

    < a href = “http://net.songtect.ru/?p=40&lol= voltmeter@irregular.balustrade”>.< / a >…

    áëàãîäàðþ….

  68. Francis Tue, 25 Feb 2014 17:45:30 UTC

    < a href = “http://wp.asphaltirovanie.ru/?p=40&lol= examination@horribly.chromatic”>.< / a >…

    thank you!…

  69. Richard Wed, 26 Feb 2014 17:38:32 UTC

    < a href = “http://catalog.artistcat.ru/?p=34&lol= sanchez@psychologically.untrue”>.< / a >…

    áëàãîäàðåí!…

  70. donnie Wed, 26 Feb 2014 18:59:04 UTC

    < a href = “http://uk.albumwork.ru/?p=25&lol= ashamd@dimensionality.iodotyrosine”>.< / a >…

    ñïàñèáî!!…

  71. marion Thu, 27 Feb 2014 00:03:50 UTC

    < a href = “http://net.albumclub.ru/?p=33&lol= recovery@operands.oratory”>.< / a >…

    áëàãîäàðåí!!…

  72. shawn Thu, 27 Feb 2014 22:11:56 UTC

    < a href = “http://eu.mp3flight.ru/?p=24&lol= snick@underlined.relaxed”>.< / a >…

    tnx for info….

  73. Daryl Fri, 28 Feb 2014 00:54:14 UTC

    < a href = “http://ch.artistcutter.ru/?p=29&lol= cha@streams.revived”>.< / a >…

    áëàãîäàðñòâóþ!!…

  74. rene Fri, 28 Feb 2014 15:12:29 UTC

    < a href = “http://uk.songferry.ru/?p=38&lol= nothin@swarming.outface”>.< / a >…

    ñïàñèáî!!…

  75. Jared Fri, 28 Feb 2014 22:01:33 UTC

    < a href = “http://cat.songloft.ru/?p=42&lol= pitiful@weighed.loveliest”>.< / a >…

    ñýíêñ çà èíôó!…

  76. Clifton Sat, 01 Mar 2014 00:26:16 UTC

    < a href = “http://com.instrumentallyrics.ru/?p=36&lol= kayabashis@reagents.kaola”>.< / a >…

    áëàãîäàðþ….

Comments