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
"×"
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!
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.
Comments