0

我收到以下错误:

Showing app/views/layouts/application.html.erb where line #15 raised:
app/views/layouts/application.html.erb:15: syntax error, unexpected keyword_end  
  ');@output_buffer.append= ( end );@output_buffer.safe_concat('
                             ^
app/views/layouts/application.html.erb:22: syntax error, unexpected keyword_ensure, expecting ')'
app/views/layouts/application.html.erb:24: syntax error, unexpected keyword_end, expecting ')'

Extracted source (around line #15):
12: <div class="container">
13:   <%= flash.each do |key, value| %>
14:       <div class="alert alert-<%= key %>"><%= value %></div>
15:   <%= end %>
16:   <%= yield %>
17:   <%= render 'layouts/footer' %>
18: </div>

以下是 application.html.erb 的内容

<!DOCTYPE html>
<html>
<head>
  <title><%= title %></title>
  <%= stylesheet_link_tag   "application", media: 'all' %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
  <%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
  <%= flash.each do |key, value| %>
      <div class="alert alert-<%= key %>"><%= value %></div>
  <%= end %>
  <%= yield %>
  <%= render 'layouts/footer' %>
</div>
</body>
</html>
4

1 回答 1

6

尝试:

 <% flash.each do |key, value| %>
   <div class="alert alert-<%= key %>"><%= value %></div>
 <% end %>

<%=表示输出,不能输出结束的结果。 <%表示执行,您可以在以下位置查看所有标签:

http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html

<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>
<%# comment -- ignored -- useful in testing %>
% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replace with <% or %> respectively
于 2012-05-09T14:14:14.437 回答