1

Given an helper like this one

def helper_method(name, &block)
  result = block_given? ? capture(&block)
  ...
  result
end

And this HAML view

= raw helper_method do
  .content
    some html content

result is nil when used with raw. why?

I know how to solve this, there is many way to avoid the situation but what I want to know is why I'm loosing the block?

Charles Barbier
  • 835
  • 6
  • 15

2 Answers2

2

Since you are not using () the block is not reaching the helper_method.

Basically the rawmethod is the one getting the block.

try : raw helper_method {}

It's one of the main differences between the do end and the {} blocks.

Or use the () to prevent the ambiguity.

Roberto Decurnex
  • 2,514
  • 1
  • 19
  • 28
  • Actually, no, I am using to pass some options (). I didn't specify to make it short, but I'll investigate in that way. Thanks for you input – Charles Barbier Jul 11 '11 at 18:34
  • I mean something like this: `raw( helper_method do ... end )`. You are having problems with the precedence. – Roberto Decurnex Jul 11 '11 at 18:38
  • I see what you mean, but in the context of Haml, I don't see how I can do this – Charles Barbier Jul 11 '11 at 18:40
  • @unixcharles In order to make it work and sort of clean I can only think about creating a `Proc` and send it as the `helper_method` param with `&` or create a `raw_helper_method` just to get the block and add the `raw` to the `helper_method` return value. HAML won't give you a clear solution here. – Roberto Decurnex Jul 11 '11 at 19:08
0

I'm not sure because i never user haml but don't you need a end tag??

like this:

<%= raw helper_method do %> 

<% end %> 

?

Nicos Karalis
  • 3,724
  • 4
  • 33
  • 62