Rails idioms?

Hello,

I am a pretty new rails (and ruby) programmer, and learning the art
and craft of rails programming. One thing I noticed about rails
programming is that unlike perl there is usually one and only one cute
and sweet way of doing a thing. Let me give 2 examples,

  1. I want to check if a variable is null and assign it a value if it’s
    null. In other languages I would write an if clause to do this, but in
    rails the sweet way would be to use the ||= operator.

  2. I want to render a table in a rails view. Normal way would be to
    write a loop, but the rails way is to use partials and pass the
    collection.

I discovered these 2 techniques recently, and it got me to think these
2 are not the only such idioms and the beauty of ruby allows lots of
such nifty techniques. But even after some googling around I am not
aware of any site where these are collected and act as resources for
programmers picking up ruby and rails. But I am sure there and such
sites and more such nice idioms in rails and ruby, but where are they?
:slight_smile:

Also what are your favorite idioms, that you would like to share?

with regards,

raj

Rajkumar S wrote:

:slight_smile:

Also what are your favorite idioms, that you would like to share?

with regards,

raj

Check out:

for lots of cool stuff (and subscribe to his blog – it’s a goldmine)

On 12/19/06, Chris T [email protected] wrote:

Select a Reject — err.the_blog
for lots of cool stuff (and subscribe to his blog – it’s a goldmine)

Very true. Thanks for the link.

raj

On Dec 18, 12:55 pm, “Rajkumar S” [email protected] wrote:

:slight_smile:

Also what are your favorite idioms, that you would like to share?

This RubyGarden page is a good reference:

http://wiki.rubygarden.org/Ruby/page/show/RubyIdioms

Best,

-r

with regards,

raj


Ryan R.
http://raaum.org
http://rails.raaum.org – Rails docs
http://locomotive.raaum.org – Self contained Rails for Mac OS X