Thursday, 30 August 2012

simplest way to comment in rhtml


The simplest way to do this is to define an a comment method in the application_helper.rb:

def comment(&block)
 #block the content
end

And use it in rhtml templates
<% comment do %>
  .. Some HTML
  .. Some ruby scriptlets
<% end %>


How this works:


def x(&block) # x is a 0 param function                                                                
    y(block) # y is a 1 param function (taking one "Proc")                                    
    z(&block) # z is a 0 param function (like x) with the block x received              
end                                                                                                                         



So, if you call z(&block) it's (nearly!!) the same as calling z { yield }: You just pass the block to the next function.