我正在这里开发一个简单的插件,到目前为止它正在工作。
除了我的帮手。
它是一个非常简单的帮助器,它只需要回显
以便以后的 javascript 解析。
问题是,它没有正确渲染 html,它用 html 等效代码替换特殊字符。
我的插件初始值设定项:
ActionView::Helpers.send :include, Test
我的插件助手:
module Test
def only_for_testing
render(:text => "<span></span>")
end
end
当我在视图内调用 only_for_testing 助手时,它不会渲染 ""
,而是渲染 "< span></span>
"
我尝试删除渲染,仅返回字符串,效果相同。
我真的不想为此创建一个部分,因为它是一个非常非常简单的html,它不是用于布局,只是用于解析。
知道我在这里可能做错了什么吗?
I'm working on a simple plugin here, and this far it is working.
Except my helper.
Its a very simple helper, it just needs to echo a <span></span>
for later javascript parsing.
The problem is, its not rendering the html correcty, its replacing special chars by the html equivalent code.
My plugin initializer:
ActionView::Helpers.send :include, Test
My plugin helper:
module Test
def only_for_testing
render(:text => "<span></span>")
end
end
When I call the only_for_testing helper inside the view, instead of rendering the "<span></span>"
it renders "<span></span>
"
I tryed remove the render, return only the string, same effect.
I really dont want to create a partial for this, because its a very very simple html, and its not for layout, its just for parsing.
Any idea what i may have done wrong here?
发布评论
评论(3)
Rails 3 默认在视图中转义 HTML。您需要使用 raw() 帮助程序或“此处的 HTML 字符串”.html_safe
Rails 3 escapes HTML by default in the view. You need to use the raw() helper or "HTML string here".html_safe
在 Rails 3.2 中,我的助手无法识别“:html”符号,
但我相信它已被替换为“:inline”,因为这对我有用
in rails 3.2, my helper did not recognize the ":html" symbol,
but I believe it's been replaced with ":inline" as this is what worked for me