17
Jun

ROR - the devil is in the details...

posted by vdimos No comments

While It has been more than a smooth ride with Rails for the last 2 years, the framework sure has some idiosyncrasies you have to get used too.

In a recent project, a small programming bug of me, caused quite a large problem.
The code was quite simple. A simple find but with following syntax:

object.find(:all, “some_id = #{something} and something else”)

while the correct syntax is

object.find(:all, :conditions => [“some_id = ? and something else”, something])

While the bug seems obvious right now, someone can grow quite easy into using this syntax when using a lot of rails ajax helpers. Their syntax is something like this:

link_to_remote(“something”, :controller => “somecontroller”, :action => “someaction”)

but this is also correct

link_to_remote(“something”, :url => {:controller => “somecontroller”, :action => someaction}}

While it is pretty clear that in one case we pass an array or string and in the other a hash is required, the message is clear.

Don’t rely too much on the magic, and never fail to question it..