actionview::template::error(nil:NilClass 的未定义方法 'html_safe') [英] actionview::template::error(undefined method 'html_safe' for nil:NilClass)
问题描述
我是 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
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屋!