Rails ApplicationHelper在没有return语句的情况下转义HTML

Rails ApplicationHelper在没有return语句的情况下转义HTML,第1张

概述当我写作 module ApplicationHelper def flash_helper flash.each do |key, msg| content_tag :div, msg, :class => key ## "<div class=\"key\">" + msg + "</div>" end endend 除非我退回声明,否 当我写作

module ApplicationHelper     def flash_helper     flash.each do |key,msg|      content_tag :div,msg,:class => key      ## "<div class=\"key\">" + msg + "</div>"    end  endend

除非我退回声明,否则我什么都得不到.当我调用<%= flash_helper%>时,HTML会在我的视图中转义.是什么赋予了?如何防止HTML被转义?

解决方法 你可以使用concat方法(Rails> = 2.2.1)

module ApplicationHelper     def flash_helper     flash.each do |key,msg|      concat(content_tag :div,:class => key)    end    nil  endend
总结

以上是内存溢出为你收集整理的Rails ApplicationHelper在没有return语句的情况下转义HTML全部内容,希望文章能够帮你解决Rails ApplicationHelper在没有return语句的情况下转义HTML所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1062336.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存