开发者

how to prevent HAML from encoding my helper method

开发者 https://www.devze.com 2023-02-07 11:15 出处:网络
So I have this on my helper: content_tag(:li, \"All\", { :onclick => %(hideAll(); document.getElementById(\"vl-body\").children[0].style.display = \"block\") } )开发者_如何学C +

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

精彩评论

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