简体   繁体   中英

Haml produces “{}” text on webpage

I am trying to convert from application.html.erb to application.haml and I get one small annoying problem being "{}" in top left corner.

问题

My code looks like this:

  %body
    = render 'shared/header'
    .container
      = flash.each do |message_type, message|
        .alert{class: "alert-#{message_type}"}= message
        -# = content_tag :div, message, class: "alert alert-#{message_type}"
      = yield
      = render 'shared/footer'

Commented out line is a second way to create div, but it produces same error.

HTML before conversion looked like this:

  <body>
    <%= render 'shared/header' %>
    <div class="container">
      <% flash.each do |message_type, message| %>
          <%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
      <% end %>
      <%= yield %>
      <%= render 'shared/footer' %>
    </div>
  </body>

What's wrong with that? How do I fix it?

It looks like you're outputting the return value of your flash.each loop

= flash.each do |message_type, message|

don't write in haml, but after a quick google it looks like maybe use

- flash.each do |message_type, message|

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM