开发者

how to prevent HAML from encoding my helper method

So I have this on my helper:

    content_tag(:li, "All", { :onclick => %(hideAll(); document.getElementById("vl-body").children[0].style.display = "block") } )开发者_如何学C +

and HAML produced this:

<li onclick="hideAll(); document.getElementById(&quot;vl-body&quot;).children[0].style.display = &quot;block&quot;">All</li>

Can't have those encoded quotes. I wanted to use the % notation instead of the double quote so appreciate help with using the % that HAML won't encode it like that.

Thanks in advance.


#your view

%li#some_id
  All

#application.js without jquery
document.getElementById('some_id').click(function(){
  hideAll(); 
  document.getElementById("vl-body").children[0].style.display = "block";
});

Alternative less opinionated answer:

content_tag(:li, "All", { :onclick => %(hideAll(); document.getElementById("vl-body").children[0].style.display = "block") } ).html_safe

I noticed the trailing plus in your content_tag code, is this important?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜