Category Archives: Rails

Block magic for Rails helpers

Ever wondered how can you have something like this

<% some_helper do %>
  Some text here
<% end %>

Well, here how it is…

def some_helper(&block)
    content = capture(&block)
    concat("this comes before the block", block.binding)
    concat(content, block.binding) # adds "Some text here" to the view
    concat("this comes after the block", block.binding)  

Neat! Isn’t it :)

Getting around the dreaded Operation Aborted error in Internet Explorer with Ruby on Rails

If you have ever experienced this…

…you know how painful it is to debug and rectify.

This error was so common that Microsoft created a knowledge base (KB927917) article for this. It even has a dedicated explanation at the IE Blog. The error basically is – “HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)”.

While building the Social sharing plugins for AdoMado, we were facing similar problems. Anywhere FB share, Orkut share or Digg buttons were being used, IE was complaining of exactly the same problem. Since social share plugins are the backbone of our community building process, fixing this ASAP was high on my agenda.

NOTE – There was no such problem on any version of Firefox or Chrome.

If you notice the IE blog entry, they mention that

Moving the location of your script block to a child of the body (this usually solves most problems, while allowing the most flexibility in terms of scenarios).

can be a possible solution.

Cool! But how do we reach here? My javascripts were spread all over the place!

First things first… I refactored the code in such a way that all possible usage of problem causing scripts was moved to one single partial. Now error was originating from only one location. The fix, as mentioned on the IE blog – was then straight forward.

In your layout, just before closing the BODY tag, use the “yield” block to render any such javascript – and render all such scripts into this “yield” block.

Here are some screen captures from our codebase…

Notice the “yield :delayed_loading” block…

Yield’ing to delayed_loading block.

If you browse over to our offer – Send Ad Free SMS using IE, you will notice that you see no such error. All the social share plugins render in harmony.
I’ve even thrown in a little jQuery fadeIn magic :)

Learning from the best!

Just bought “Programming Ruby 1.9” from Flipkart.

From For Blog

When I joined IBM ISS UI team and my tech lead suggested that we should start doing things in Rails- and I was prompt enough to pop up a suggestion – “that why don’t we use Python based web app frameworks Django or Turbo Gears (as I had some python experience)”.

All he replied was – “when we are looking for the best framework, why not use the one everyone’s trying to become”.

And hence, the awesome journey to Rails began.
Understanding Ruby better will make it so much more fun.

PS: No disrespect meant to the awesome work being put in by the Python community. Python rocks! So does Ruby!