我收到以下错误:
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>
答案 0 :(得分: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