<%= if flash[:notice]%> Ruby on Rails 中的语法错误

Die*_*ios 1 ruby ruby-on-rails erb

有问题的代码:

<%= 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 %>
Run Code Online (Sandbox Code Playgroud)

运行我的服务器时,会出现以下错误: 在此处输入图片说明

已将语法更改为:if (flash[:notice])。但是,还是放下这个。任何的想法?

top*_*oon 6

<%= if flash[:notice] %>
Run Code Online (Sandbox Code Playgroud)

上面的代码应该是:

<% if flash[:notice] %>
Run Code Online (Sandbox Code Playgroud)

笔记

<% %> - 执行括号内的 ruby​​ 代码。

<%= %> - 将某些内容打印到 ERB 文件中。