开发者

helper with block and raw

开发者 https://www.devze.com 2023-03-19 05:58 出处:网络
Given an helper like this one def helper_method(name, &block) result = block_given? ? capture(&block)

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 situatio开发者_开发技巧n but what I want to know is why I'm loosing the block?


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.


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

like this:

<%= raw helper_method do %> 

<% end %> 

?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号