actionview::template::error(nil:NilClass 的未定义方法 'html_safe') [英] actionview::template::error(undefined method 'html_safe' for nil:NilClass)

查看:51
本文介绍了actionview::template::error(nil:NilClass 的未定义方法 'html_safe')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ruby​​ 的初学者,我想为 redmine 编写一个插件.我编写了一个插件,自从我在插件的控制器中使用 'flash[:var]' 以来,该插件一直在运行.现在,当我想访问我的所有页面时,我收到一条我不明白的错误消息.

Ruby 版本:ruby 1.9.3p484

Rails 版本:rails 3.2.19

感谢您的回答.

解决方案

您似乎遇到过 nil 值在 flash 中的情况.假设你有一个 flash{ error: nil },那么你会在 content_tag 中调用 v.html_safe- 什么会导致错误.

您可能希望在调用 content_tag 之前从 flash 中提取所有 present 的值?:

def render_flash_messagesflash.select { |k, v|v.现在?}.map do |type, text|content_tag(:div, text.html_safe, class: "flash #{type}", id: "flash_#{typ}")结束连接结尾

I am a beginer in ruby and I want to write a plugin for redmine. I have written a plugin which was running since I use 'flash[:var]' in a controller of my plugin. Now when I want to access to all my pages I have an error message that I not understand.

Ruby version : ruby 1.9.3p484

Rails version : rails 3.2.19

this is the error message

thank you for your answers.

EDIT:

this is the application_helper

解决方案

It seems like you ran into situations in which you have nil values in your flash. Imagine you have a flash like { error: nil }, then you would call v.html_safe in the content_tag - what will cause the error.

You might want to extract all values from the flash that are present?, before calling content_tag:

def render_flash_messages
  flash.select { |k, v| v.present? }.map do |type, text|
    content_tag(:div, text.html_safe, class: "flash #{type}", id: "flash_#{typ}")
  end.join
end

这篇关于actionview::template::error(nil:NilClass 的未定义方法 'html_safe')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆