Rails 语法错误,意外 keyword_ensure,预期 keyword_end
Rails syntax error, unexpected keyword_ensure, expecting keyword_end
我正在尝试使用 acts_as_taggable_on gem 让两种不同类型的标签工作。我正在关注 this link. 我收到此错误:
语法错误,意外 keyword_ensure,预期 keyword_end
语法错误,意外的输入结束,期望 keyword_end
错误说问题出在我的 show.html.erb 的第 92 行,但是当我把 <% end %> 放在那里时,它并没有解决它。
show.html.erb
<%- title "#{@artwork.title} — a #{@artwork.category.downcase} by Peter Bentley"%>
<% if user_signed_in? %>
<div class="row">
<div class="col-md-12">
<%= link_to 'Edit', edit_artwork_path(@artwork) %> |
<%= link_to 'Artworks Table', admin_path %>
</div>
</div>
<% end %>
<div class="row">
<div class="col-md-8">
<%= image_tag(@artwork.image.url, :class => 'img-responsive') %>
</div>
<div class="col-xs-12 col-md-4">
<p class="field-label">Title</p>
<h1><%= @artwork.title %></h1>
</div>
<div class="col-xs-6 col-sm-3 col-md-4">
<p class="field-label">Medium</p>
<h3><%= @artwork.medium %></h3>
</div>
<% unless @artwork.date.blank? %>
<div class="col-xs-6 col-sm-3 col-md-2">
<p class="field-label">Date</p>
<h3><%= @artwork.date.strftime("%b %d %Y") %></h3>
</div>
<% end %>
<% unless @artwork.height.blank? | @artwork.width.blank?%>
<div class="col-xs-6 col-sm-3 col-md-4">
<p class="field-label">Size</p>
<h3><%= @artwork.height %> x <%= @artwork.width %> in.</h3>
</div>
<% end %>
<div class="col-xs-6 col-sm-3 col-md-2">
<p class="field-label">Genre</p>
<h3><%= @artwork.genre %></h3>
</div>
<div class="col-xs-6 col-sm-3 col-md-2">
<p class="field-label">Category</p>
<h3><%= @artwork.category %></h3>
</div>
<% unless @artwork.availability.blank? %>
<div class="col-xs-12 col-sm-3 col-md-4">
<% if @artwork.availability == 'Available for purchase' %>
<p class="field-label">Availability</p>
<h3><%= @artwork.availability %></h3>
<%= link_to "Add to Inquiry List", root_path, class: "btn btn-primary" %>
<% else %>
<p class="field-label">Availability</p>
<h3><%= @artwork.availability %></h3>
<% end %>
</div>
<% end %>
<% unless @artwork.series.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Series</p>
<% @artwork.series.each do |series| %>
<span class="tags">
<%= link_to series.name, series_url(:series => series.name) %>
</span>
</div>
<% end %>
<% unless @artwork.tags.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Tags</p>
<% @artwork.tags.each do |tag| %>
<span class="tags">
<%= link_to tag.name, tagged_url(:tag => tag.name) %>
</span>
</div>
<% end %>
</div> <!-- end of 'row' div -->
<div class="fixed-prev-next">
<div class="btn-group" role="group" aria-label="...">
<%= link_to "Previous", @artwork.previous, :class => "btn btn-default" if @artwork.previous.present? %>
<%= link_to "Next", @artwork.next, :class => "btn btn-default" if @artwork.next.present? %>
</div>
</div>
<% end %>
artworks_controller.erb 有
def index
if params[:tag]
@artworks = Artwork.tagged_with(params[:tag])
else
@artworks = Artwork.all
end
end
def tagged
if params[:tag].present?
@artworks = Artwork.tagged_with(params[:tag])
else
@artworks = Artwork.all
end
end
def series
if params[:series].present?
@artworks = Artwork.tagged_with(params[:series])
else
@artworks = Artwork.all
end
end
和允许的私有方法
:tag_list, :tag, :series_list, :series
artwork.rb 有
acts_as_taggable
acts_as_taggable_on :tags, :series
我做错了什么?
您未能使用 <% end %>
.
关闭 2 个循环
<% unless @artwork.series.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Series</p>
<% @artwork.series.each do |series| %>
<span class="tags">
<%= link_to series.name, series_url(:series => series.name) %>
</span>
<%# Need end here, as illustrated on the next line. %>
<% end %>
</div>
<% end %>
<% unless @artwork.tags.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Tags</p>
<% @artwork.tags.each do |tag| %>
<span class="tags">
<%= link_to tag.name, tagged_url(:tag => tag.name) %>
</span>
<%# Need end here, as illustrated on the next line. %>
<% end %>
</div>
<% end %>
更加注意代码的缩进方式。它很重要,可以帮助您更轻松地预防和调试此类语法问题。
我正在尝试使用 acts_as_taggable_on gem 让两种不同类型的标签工作。我正在关注 this link. 我收到此错误:
语法错误,意外 keyword_ensure,预期 keyword_end 语法错误,意外的输入结束,期望 keyword_end
错误说问题出在我的 show.html.erb 的第 92 行,但是当我把 <% end %> 放在那里时,它并没有解决它。
show.html.erb
<%- title "#{@artwork.title} — a #{@artwork.category.downcase} by Peter Bentley"%>
<% if user_signed_in? %>
<div class="row">
<div class="col-md-12">
<%= link_to 'Edit', edit_artwork_path(@artwork) %> |
<%= link_to 'Artworks Table', admin_path %>
</div>
</div>
<% end %>
<div class="row">
<div class="col-md-8">
<%= image_tag(@artwork.image.url, :class => 'img-responsive') %>
</div>
<div class="col-xs-12 col-md-4">
<p class="field-label">Title</p>
<h1><%= @artwork.title %></h1>
</div>
<div class="col-xs-6 col-sm-3 col-md-4">
<p class="field-label">Medium</p>
<h3><%= @artwork.medium %></h3>
</div>
<% unless @artwork.date.blank? %>
<div class="col-xs-6 col-sm-3 col-md-2">
<p class="field-label">Date</p>
<h3><%= @artwork.date.strftime("%b %d %Y") %></h3>
</div>
<% end %>
<% unless @artwork.height.blank? | @artwork.width.blank?%>
<div class="col-xs-6 col-sm-3 col-md-4">
<p class="field-label">Size</p>
<h3><%= @artwork.height %> x <%= @artwork.width %> in.</h3>
</div>
<% end %>
<div class="col-xs-6 col-sm-3 col-md-2">
<p class="field-label">Genre</p>
<h3><%= @artwork.genre %></h3>
</div>
<div class="col-xs-6 col-sm-3 col-md-2">
<p class="field-label">Category</p>
<h3><%= @artwork.category %></h3>
</div>
<% unless @artwork.availability.blank? %>
<div class="col-xs-12 col-sm-3 col-md-4">
<% if @artwork.availability == 'Available for purchase' %>
<p class="field-label">Availability</p>
<h3><%= @artwork.availability %></h3>
<%= link_to "Add to Inquiry List", root_path, class: "btn btn-primary" %>
<% else %>
<p class="field-label">Availability</p>
<h3><%= @artwork.availability %></h3>
<% end %>
</div>
<% end %>
<% unless @artwork.series.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Series</p>
<% @artwork.series.each do |series| %>
<span class="tags">
<%= link_to series.name, series_url(:series => series.name) %>
</span>
</div>
<% end %>
<% unless @artwork.tags.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Tags</p>
<% @artwork.tags.each do |tag| %>
<span class="tags">
<%= link_to tag.name, tagged_url(:tag => tag.name) %>
</span>
</div>
<% end %>
</div> <!-- end of 'row' div -->
<div class="fixed-prev-next">
<div class="btn-group" role="group" aria-label="...">
<%= link_to "Previous", @artwork.previous, :class => "btn btn-default" if @artwork.previous.present? %>
<%= link_to "Next", @artwork.next, :class => "btn btn-default" if @artwork.next.present? %>
</div>
</div>
<% end %>
artworks_controller.erb 有
def index
if params[:tag]
@artworks = Artwork.tagged_with(params[:tag])
else
@artworks = Artwork.all
end
end
def tagged
if params[:tag].present?
@artworks = Artwork.tagged_with(params[:tag])
else
@artworks = Artwork.all
end
end
def series
if params[:series].present?
@artworks = Artwork.tagged_with(params[:series])
else
@artworks = Artwork.all
end
end
和允许的私有方法
:tag_list, :tag, :series_list, :series
artwork.rb 有
acts_as_taggable
acts_as_taggable_on :tags, :series
我做错了什么?
您未能使用 <% end %>
.
<% unless @artwork.series.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Series</p>
<% @artwork.series.each do |series| %>
<span class="tags">
<%= link_to series.name, series_url(:series => series.name) %>
</span>
<%# Need end here, as illustrated on the next line. %>
<% end %>
</div>
<% end %>
<% unless @artwork.tags.blank? %>
<div class="col-xs-6 col-sm-6 col-md-4">
<p class="field-label">Tags</p>
<% @artwork.tags.each do |tag| %>
<span class="tags">
<%= link_to tag.name, tagged_url(:tag => tag.name) %>
</span>
<%# Need end here, as illustrated on the next line. %>
<% end %>
</div>
<% end %>
更加注意代码的缩进方式。它很重要,可以帮助您更轻松地预防和调试此类语法问题。