【问题标题】:Action Controller: Exception caught - Agile Web Development with Rails动作控制器:捕获异常 - 使用 Rails 进行敏捷 Web 开发
【发布时间】:2012-06-07 16:44:17
【问题描述】:

我一直在阅读使用 Rails 进行敏捷 Web 开发,我目前在第 75/76 页上为产品设置视图。

我运行 rails 得到的是这个异常。

*C:/Users/Win7/Desktop/Agile/depot/app/views/products/index.html.erb:25: 语法错误,出乎意料的keyword_end,期待')' ');结尾 ^ C:/Users/Win7/Desktop/Agile/depot/app/views/products/index.html.erb:34: 语法错误,意外的keyword_ensure,需要')' C:/Users/Win7/Desktop/Agile/depot/app/views/products/index.html.erb:36: 语法错误,意外的keyword_end,需要')'*

这是视图中的代码:

<h1>Listing products</h1>

<table>
<% @products.each do |product| %>
<tr class="<%= cycle('list_line_odd', 'list_line_even') %>">
<td>
  <%= image_tag(product.image_url, class: 'list_image') %>
</td>

<td class="list_description">
  <dl>
    <dt><%= product.title %></dt>
    <dd><%= truncate(strip_tags(product.description), length: 80 %></dd>
  </dl>
</td>

<td class="list_actions">
  <%= link_to 'Show', product %><br />
  <%= link_to 'Edit', edit_product_path(product) %><br />
  <%= link_to 'Destroy', product, confirm: 'Are you sure?', method: :delete %>
</td>
</tr>

<% end %>

</table>


<br />

<%= link_to 'New Product', new_product_path %>

我不知道为什么会出现此异常。有人能解释一下吗?

一如既往,非常感谢!

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    删除您在此文件中的结尾:

    <% end %>
    

    这一端没有关闭任何东西。

    【讨论】:

      【解决方案2】:

      你少了一个 ) 就行了

       truncate(strip_tags(product.description), length: 80 
      

      应该是

       truncate(strip_tags(product.description), length: 80) 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-30
        • 2012-09-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多