【问题标题】:rails 3 is printing html tags to screen instead of rendering themrails 3 正在将 html 标签打印到屏幕而不是渲染它们
【发布时间】:2010-08-01 14:00:36
【问题描述】:

我正在使用 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,希望 hochstein 先生能够使用这些东西。

【问题讨论】:

    标签: ruby-on-rails activescaffold ruby-on-rails-3


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 太棒了!你修好了。我已经通过电子邮件向 gitrepo 所有者发送了电子邮件,让他知道该线程,以便他可以将其合并到他的代码中。非常感谢
    • 我分叉了 active_scaffold 并添加了修复 github.com/murdoch/active_scaffold
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多