What's wrong with this code in Ruby on Rails and HAML?

yassine2020

My Ruby on Rails version is 4.2.3, this is a helper in application_helper.rb it suppose to print flash notifications in views/layouts/application.html.haml

def flash_message key, message, dismissible
    dismiss = dismissible ? " alert-dismissible" : ""
    content_tag :div, class: flash_class(key.to_sym) + dismiss do
                if dismissible
                    content_tag(:button, {type: "button", class: "close", "data-dismiss" => "alert", "aria-label" => "Close"}) do
                        content_tag :span, {"aria-hidden" => "true"} do
                            "&times"
                        end
                    end
                end

                content_tag :span, class: "glyphicon glyphicon-ok"

                message
            end
end

On views/layouts/application.html.haml

- if flash.any?
            - flash.each do |key, message|
                    = flash_message key, message, true

It doesn't display all the content it only displays the first div with class and the message which is fine but I still need the close button if the flash message is dismissible and the span with glyphicon class.

<div class="alert alert-success alert-dismissible">message</div>

Thank you!

yassine2020

As SergioTulentsev suggested the content_tag should be concatenated but for the helper function to parse HTML properly not literally the message variable should be followed by .html_safe method.

Thanks for everyone's help.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the difference between Haml and Yaml in Ruby on Rails?

From Dev

what is wrong with this ruby inheritance code?

From Dev

What is the difference between = and - in haml while writing ruby code?

From Dev

Writing ruby code in a haml string

From Dev

HAML / Ruby - Code Helper Blocks

From Dev

Explain this HAML and Ruby weird code

From Dev

What's wrong with this code block?

From Dev

what's wrong with the golang code

From Dev

What's wrong with this encryption code?

From Dev

What's wrong with this RxUI code?

From Dev

what's wrong with this opencv code

From Dev

what's wrong with this code at sessionloginid

From Dev

What's wrong with this code? (Javascript)

From Dev

What's wrong with this code in ARM

From Dev

What's wrong with the Javascript code?

From Dev

What's wrong with this RxUI code?

From Dev

What's wrong with this JSON code?

From Dev

PHP: What's wrong with this code?

From Dev

What's wrong with this flex code?

From Dev

What is wrong with this Ruby case control code?

From Dev

what's << in ruby on rails model

From Dev

Project Euler #17 Ruby - What's wrong?

From Dev

What's wrong in this Code? Netbeans not compiling the code

From Dev

inject values into javascript using haml on ruby on rails

From Dev

Errors in my haml file in a ruby on rails project

From Dev

Rails / Bootstrap / HAML - How to convert this code to display flash messages to HAML?

From Dev

What am I doing wrong Ruby on Rails facebook login

From Dev

haml use ruby code and plain text

From Dev

What's wrong with this simplest jflex code?