Rails 3 将 html 标签打印到屏幕上而不是渲染它们

发布于 2024-09-12 00:30:27 字数 1145 浏览 2 评论 0原文

我正在使用 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 标签被打印出来,如下图所示:

https://internet-websites.s3.amazonaws.com/image2886.png

如何使此 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:

https://internet-websites.s3.amazonaws.com/image2886.png

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2024-09-19 00:30:28

试试这个:

return "<a class='disabled'>#{text}</a>".html_safe unless authorized

Try this:

return "<a class='disabled'>#{text}</a>".html_safe unless authorized
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文