Search code examples
ruby-on-railsrubyredmineredmine-plugins

actionview::template::error(undefined method 'html_safe' for nil:NilClass)


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 The error message

thank you for your answers.

EDIT:

this is the application_helper

the application_helper


Solution

  • 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