Reputation: 17
i use haml and i want to use flash messsages but i have a syntax error, when create the partial _messages.html.haml and rendering in the devise.html.haml i have this error:
ActionView::SyntaxErrorInTemplate in Devise::SessionsController#new
Encountered a syntax error while rendering template: check - flash.each do |name, msg| - if msg.is_a?(String) %br %div{:class => "alert alert-#{name.to_s == 'notice' ? 'success' : 'danger'}"} %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × = content_tag :div, msg, :id => "flash_#{name}"
Extracted source (around line #8):
6 = content_tag :div, msg, :id => "flash_#{name}"
> Rails.root: /organizator Application
> Trace | Framework Trace | Full Trace
> app/views/layouts/_messages.html.haml:8: syntax error, unexpected
> end-of-input, expecting `end' app/views/layouts/_messages.html.haml:8:
> syntax error, unexpected end-of-input, expecting `end'
> app/views/layouts/_messages.html.haml:8: syntax error, unexpected
> end-of-input, expecting `end' app/views/layouts/_messages.html.haml:8:
> syntax error, unexpected end-of-input, expecting `end'
> app/views/layouts/_messages.html.haml:8: syntax error, unexpected
> end-of-input, expecting `end' app/views/layouts/_messages.html.haml:8:
> syntax error, unexpected end-of-input, expecting `end'
> app/views/layouts/devise.html.haml:13
Exception Causes
SyntaxError: /organizator/app/views/layouts/_messages.html.haml:8: syntax error, unexpected end-of-input, expecting `end'
in the terminal i have this:
> ActionView::SyntaxErrorInTemplate (Encountered a syntax error while
> rendering template: check - flash.each do |name, msg|
> - if msg.is_a?(String) %br %div{:class => "alert alert-#{name.to_s == 'notice' ? 'success' : 'danger'}"} %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × =
> content_tag :div, msg, :id => "flash_#{name}" ): 1: - flash.each do
> |name, msg| 2: - if msg.is_a?(String) 3: %br 4:
> %div{:class => "alert alert-#{name.to_s == 'notice' ? 'success' :
> 'danger'}"} 5: %button.close{"aria-hidden" => "true",
> "data-dismiss" => "alert", :type => "button"} × 6: =
> content_tag :div, msg, :id => "flash_#{name}"
>
> app/views/layouts/_messages.html.haml:8: syntax error, unexpected
> end-of-input, expecting `end' app/views/layouts/_messages.html.haml:8:
> syntax error, unexpected end-of-input, expecting `end'
> app/views/layouts/_messages.html.haml:8: syntax error, unexpected
> end-of-input, expecting `end' app/views/layouts/_messages.html.haml:8:
> syntax error, unexpected end-of-input, expecting `end'
> app/views/layouts/_messages.html.haml:8: syntax error, unexpected
> end-of-input, expecting `end' app/views/layouts/_messages.html.haml:8:
> syntax error, unexpected end-of-input, expecting `end'
> app/views/layouts/devise.html.haml:13
My devise template devise.html.haml app/views/layouts/devise.html.haml
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title Tasker
= csrf_meta_tags
= csp_meta_tag
= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
%body
.container
.main-flash-messages
= render 'layouts/messages'
.fullscreen
.container
= yield
My partial _messages.html.haml app/views/layouts/_messages.html.haml
- flash.each do |name, msg|
- if msg.is_a?(String)
%br
%div{:class => "alert alert-#{name.to_s == 'notice' ? 'success' : 'danger'}"}
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
= content_tag :div, msg, :id => "flash_#{name}"
I tryed to solve this reading the documentation of haml but i don't know what is wrong. Regards.
Upvotes: 0
Views: 293
Reputation: 106932
I am not familiar with HAML but I expect that the content that depends on the if
condition needs to be indented and would therefore try:
- flash.each do |name, msg|
- if msg.is_a?(String)
%br
%div{:class => "alert alert-#{name.to_s == 'notice' ? 'success' : 'danger'}"}
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
= content_tag :div, msg, :id => "flash_#{name}"
Upvotes: 1