Search code examples
ruby-on-railsrubyerb

Syntax error in <%= if flash[:notice]%> Ruby on Rails


The probleming code:

<%= if flash[:notice] %>
  <div class="notification is-primary global-notification">
    <p class="notice"><%= notice %></p>
  </div>
<% end %>
<%= if flash[:alert] %>
  <div class="notification is-danger global-notification">
    <p class="alert"><%= alert %></p>
  </div>
<% end %>

And when running my server the following error drops: enter image description here

Already changed the syntax to: if (flash[:notice]). But still, drop this. Any idea?


Solution

  • <%= if flash[:notice] %>
    

    The above code should be:

    <% if flash[:notice] %>
    

    Note

    <% %> - Executes the ruby code within the brackets.

    <%= %> - Prints something into ERB file.