views:

168

answers:

1

I am writing a Rails helper method that will add wrapper html to captured content blocks and replace content_for method, such as

- content_for :header do
 //haml code

..would become

- content :header do
 //haml code

In order to do this I am using Haml and Ruby blocks. This is what it looks like

def content(name,&block)
 content_for name do
   capture_haml do
     haml_tag "div",{:id=>name.to_s} do
       haml_tag "div",{:id=>"#{name.to_s}_group"} do
         block
       end  
     end    
   end      
 end  
end

But I can't get this to work. There is no error message. It just doesn't show the block at all! I'm not sure what I am doing wrong. I'd appreciate a second opinion.

+3  A: 

You're doing roughly the right thing, but you aren't actually calling the block #content is passed. To do so, either use block.call, or Ruby's built-in yield statement.

nex3