ronny.haryan.to

Icon

Print: $9.50 — Online: free

Ruby on Rails

Rails logoI finally got a chance to play around with Ruby on Rails. I looked around for a simple and straightforward tutorial that covers the basic, and settled with Curt Hibbs’ Rolling with Ruby on Rails on ONLamp.com. It’s a two-part article. Not overly long to follow, like 30 minutes or so (including searching and reading some API documentation), and I got a functional application at the end of the tutorial. All without too much knowledge about Ruby language, just have some prior understanding of the MVC (model-view-controller) model general concept and you’re all set.

Ruby on Rails is what J2EE should have been.

Oh, man, was I ever excited! After finishing that tutorial, I immediately searched for information about the existance of an Oracle adapter for ActiveRecord. It turned out that there is one, it’s included in recent versions of ActiveRecord and is based on the ruby-oci8 driver. I started my development Oracle server and immediately generated a scaffold for a test model. There were two minor problems. The first problem was that my table and column names did not follow the proper naming conventions expected by Rails, so I had to override it in the model class with set_table_name (doc) and set_primary_key (doc). No worries. The second problem was that the web server seemed to freeze after about 5-10 seconds of inactivity. It must have been something to do with the oci8 driver or ActiveRecord’s oci8 implementation, because it worked flawlessly with mysql. I didn’t have time to investigate further. It was good enough for me for now. I’m sure if it really was a problem with the driver then someone more knowledegable will catch it real soon and we’ll have a fix.

So, in conclusion, I wish Ruby on Rails had existed many years ago therefore, it could save me many weeks worth of tedious and error-prone coding. It beats PHP and J2EE any day. I will definitely use Ruby on Rails for my next web development project. And to summarize for those of you that are lazy or don’t have the time to follow the tutorial, install Ruby on Rails, then create a table in your database called products with these columns: id, name, description. Then create the rails structure with rails productlist, go inside the newly-created productlist directory, edit config/database.yml accordingly then run ruby script/generate scaffold Product. Then run the built-in WEBrick web server with ruby script/server then open your browser and go to http://127.0.0.1:3000/products. Voilà! That was ‘hard’. Now you can concentrate on what’s important, your application and its design, not tedious, repetitive and error-prone coding.

Category: Web Development

Tagged:

10 Responses

  1. Tomi T says:

    Bbrp bulan lalu saya mulai mencoba2 RoR, kelihatannya memang mempermudah banyak hal dan saya jadi lebih tertarik untuk mempelajarinya.
    Tapi kok hal2 yang gampangnya cuma di simple CRUD.

    Kalau model nya punya relationship yg lebih kompleks, sepertinya sudah tidak semudah spt contoh ‘Products’ itu.

    Misalnya jika mengupdate product berarti mengupdate beberapa item, beberapa order atau invoice, code nya jadi tidak semudah contoh Products itu.

    Tolong koreksi saya kalau pengertian saya salah.

  2. Hey! I’ve been enjoying web app development with Rails over the last few months and I agree with you! It’s what a web development framework should have been, years ago. If you haven’t already, join the mailing list (http://lists.rubyonrails.org/mailman/listinfo/rails) There are a lot of friendly, helpful people over there.

  3. ronny says:

    Saya rasa kekuatan rails memang mempermudah di hal2 yg simple seperti CRUD itu karena memang pada dasarnya kebanyakan aplikasi itu customisation dari atau build on top yg simple CRUD ini. Sehingga kita tidak usah cape2 dan buang waktu utk hal2 yg sepele seperti ini.

    Nah untuk business logicnya ya tentu saja tidak bisa ditebak atau digeneralisasi, jadi mau gak mau mesti kita tulis sendiri. Yg seperti anda contohkan di atas itu termasuk business logic menurut saya.

    I guess my point is, untuk the first stepnya itu rails lebih cepat drpd yg lain yg udah saya cobain. Soalnya saya juga belum nyobain lebih lanjut. Tapi dr perasaan saya sih (karena belum nyoba lebih lanjut) rails bisa sedikit lebih cepat drpd yg lain juga walaupun mungkin tidak sedrastis first step ini, asalkan cara kita benar. Ini karena pembagian MVC yg jelas dan efektif, efektifnya itu karena mudah dan straightforward banget kalo mau nambahin apa2 di controllernya misalnya.

  4. ronny says:

    Thanks FYI, Duane. I’m on the list now! :D

  5. That’s funny, I’ve been reading the same stuffs you read this weekend.

  6. ronny says:

    William, no way.. you’re reading “Asterix and Cleopatra”, too? :p

  7. Unfortunately, I didn’t read “Asterix and Cleopatra” :P

    Have you heard about Cake PHP Framework – http://sputnik.pl/cake/docs/intro

  8. ronny says:

    I haven’t heard about Cake before. There are similar implementations for Java and Perl as well:

    https://trails.dev.java.net/
    http://www.perl.com/pub/a/2004/04/15/maypole.html
    http://www-106.ibm.com/developerworks/linux/library/l-maypole/?ca=dgr-perlw02BuildMypole

    I saw all of these links from the comments to Curt’s article I mentioned in my post.

  9. arie says:

    Irashaimasu.. welcome to the wonderful land of ruby (rails) :) don’t forget to join our indonesian mailing list id-ruby@yahoogroups.com i’m sure it’ll be fun to share many things (about ruby, rails, erb, etc) with such a smart one/hacker like you sir ..
    b’fore u reject my complement, i said so, because u’ve talked about oracle & rails and active record too. active record is considered to be an advanced topic you know. plus u said didn’t know that much about ruby.
    i personally will be happy to get smart “poisons” from yours :) my! i need to learn a lot from u sensei ronny-san.

    oh, about CRUD is the only amazing thing that makes our code simple? you and pak tomi can explore more about ajax, also a magic word of @content_for_layout which reminds me of php-smarty and pear/engine system, juga tentang gimana rails ng-handle SQL dengan find(*args) & keluarganya di active record. there are still lots of rails’ magic to make us (ruby programmers) to laugh more than others :D coz we can make our apps in no time with less code

    rails == le même plus meilleur à le monde avant la premiere version.

  10. Harry says:

    Don’t forget Ruby Gems, it’ll help you a lot on keeping your Rails installation up to date (very important these days)

    Sayang saya masih belum juga sempat oprek-oprek Rails :( hik

About

Ronny Haryanto is a technology addict/chef wannabe living in beautiful Melbourne, Australia.

Read more…

Follow Me on Twitter

Follow @ronny on Twitter where I post much more often than my blog.