加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – rails 3将html标签打印到屏幕而不是渲染它们

发布时间:2020-12-17 01:44:26 所属栏目:百科 来源:网络整理
导读:我正在使用vhochstein的active_scaffold分支,它在rails 3上运行得非常好,除了一些小错误 – http://github.com/vhochstein/active_scaffold. 在rails 2.3中,以下代码禁用链接: return "a class='disabled'#{text}/a" unless authorized 但是在Rails 3中,它
我正在使用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文件

更新:

通过建议将.html_safe添加到代码中,Floatless修复此问题.

我已经发现还需要进行以下更改,因为有多个代码可以响应在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 -%>

无论如何,多亏了浮动,希望hochstein先生能够使用这些东西.

解决方法

试试这个:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读