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:

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

>

Check out:
http://errtheblog.com/post/44
for lots of cool stuff (and subscribe to his blog -- it's a goldmine)

Very true. Thanks for the link.

raj

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?

This RubyGarden page is a good reference:

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

Best,

-r