Rails语法错误,意外的keyword_ensure,期待keyword_end

时间:2015-02-03 14:56:58

标签: ruby-on-rails ruby-on-rails-4 acts-as-taggable-on

我正在尝试使用acts_as_taggable_on gem获取两种不同类型的标签。我跟着this link.我收到了这个错误:

语法错误,意外的keyword_ensure,期待keyword_end yntax错误,意外的输入结束,期待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 %>

artwork_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

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您未能使用<% 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 %>

更加关注如何缩进代码。它很重要,可以帮助您更轻松地防止和调试这样的语法问题。