我使用 haml 并且我想使用 flash 訊息,但是我有一個語法錯誤,當創建部分 _messages.html.haml 并在 devise.html.haml 中呈現時我有這個錯誤:
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'
在終端我有這個:
> 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
我的設計模板 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
我的部分 _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}"
我試圖通過閱讀haml的檔案來解決這個問題,但我不知道出了什么問題。問候。
uj5u.com熱心網友回復:
我不熟悉 HAML,但我希望取決于if條件的內容需要縮進,因此會嘗試:
- 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}"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/404416.html
標籤:
