Rails 3 将 html 标签打印到屏幕上而不是渲染它们
我正在使用 vhochstein 的 active_scaffold 分支,它在 Rails 3 上运行得很好,除了一些小错误 - http: //github.com/vhochstein/active_scaffold。
在 Rails 2.3 中,以下代码禁用链接:
return "<a class='disabled'>#{text}</a>" unless authorized
但在 Rails 3 中,它会导致转义的 html 标签被打印出来,如下图所示:
如何使此 return 语句的内容呈现Rails 3 中应该这样吗?
上面的代码来自于vendor/plugins/active_scaffold/helpers/中的list_column_helpers.rb
文件
更新:
Floatless通过建议将.html_safe
添加到代码中修复了这个问题。
我发现还需要进行以下更改,因为有不止一位代码可响应在 active_Scaffold 中禁用操作链接:
在 /plugins/active_scaffold/frontends/default/views/_list_actions.html.erb 更改中:
<%= record.authorized_for?(:crud_type => etc etc etc -%>
By making it use "raw"
i.e.
<%= raw record.authorized_for?(:crud_type => etc etc etc -%>
不管怎样,感谢 floatless,希望霍赫斯坦先生能够使用这个东西。
I'm using vhochstein's fork of active_scaffold, which runs quite nicely on rails 3, except for a few small bugs - http://github.com/vhochstein/active_scaffold.
In rails 2.3, the following code disables a link:
return "<a class='disabled'>#{text}</a>" unless authorized
But in Rails 3, it causes the escaped html tags to be printed out instead as in the following photo:
How can I make the content of this return statement render the way it should in rails 3?
The code above, is from the list_column_helpers.rb
file in vendor/plugins/active_scaffold/helpers/
UPDATE:
Floatless fixed this by suggesting to add .html_safe
to the code.
I have since found that the folowing change also needs to be made as there's more than one bit of code that is respondible for disabling action links in active_Scaffold:
In /plugins/active_scaffold/frontends/default/views/_list_actions.html.erb change:
<%= record.authorized_for?(:crud_type => etc etc etc -%>
By making it use "raw"
i.e.
<%= raw record.authorized_for?(:crud_type => etc etc etc -%>
Anyway, thanks to floatless and hopefully mr hochstein will be able to use this stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: