在HAML中转义内联链接 [英] Unescaping inline links in haml
问题描述
因此,我尝试在电子邮件表单的标题旁获取删除链接.但是,我的rails voodoo显然非常虚弱.它转义了HTML,我不知道如何避免这种情况.有提示吗?
So I'm trying to get a remove link next to the caption in an emails form. However, my rails voodoo is clearly very weak. It escapes the HTML and I can't figure out how to get it to not. Any hints?
= f.input :email, :label => "Email " + link_to_remove_fields("[x]", f)
[edit]哦,是的,这也做同样的事情:
[edit] oh and yes, this does the same thing:
= f.input :email, :label => "Email #{link_to_remove_fields("[x]", f)}"
这是我的助手方法...
and here's my helper method...
def link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")
end
推荐答案
我遇到了与此相同的问题,我通过在帮助器中使用以下命令解决了该问题:
I had the same issue as this, I fixed it by using the following in my helper:
link_to_function(name, "add_fields(this, '#{association}', \'#{escape_javascript(fields)}\')")
需要注意的一件事是,当我在Rails 3.1应用程序中尝试此操作时,必须先重新启动服务器,然后再获取帮助程序中的更改.对于早期版本,这可能是正确的,也可能不是正确的,但请记住.
One thing to note, when I tried this in a Rails 3.1 app I had to restart the server before changes in the helper were picked up. This may or may not be true for earlier versions but worth keeping in mind.
这篇关于在HAML中转义内联链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!