-1

在我的 rails 应用程序中,仅使用脚手架生成的视图以及引导程序,我收到了一个动作控制器错误:

SyntaxError in Orders#index

Showing /Users/Michael/Documents/Morning_Coffee/app/views/orders/index.html.erb where line #39 raised:

/Users/Michael/Documents/Morning_Coffee/app/views/orders/index.html.erb:39: syntax error, unexpected keyword_ensure, expecting ')'
/Users/Michael/Documents/Morning_Coffee/app/views/orders/index.html.erb:41: syntax error, unexpected keyword_end, expecting ')'
Extracted source (around line #39):

36: 
37: <%= link_to t('.new', :default => t("helpers.links.new")), new_order_path, :class =>       'btn btn-primary' %>
Trace of template inclusion: app/views/orders/index.html.erb

Rails.root: /Users/Michael/Documents/Morning_Coffee

Application Trace | Framework Trace | Full Trace
app/controllers/orders_controller.rb:7:in `index'

这是 index.html:

<%- model_class = Order.new.class -%>
    <h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
    <table class="table table-striped">
      <thead>
        <tr>
          <th><%= model_class.human_attribute_name(:id) %></th>
          <th><%= model_class.human_attribute_name(:drink %></th>
          <th><%= model_class.human_attribute_name(:time) %></th>
          <th><%= model_class.human_attribute_name(:price) %></th>
          <th><%= model_class.human_attribute_name(:created_at) %></th>
          <th><%=t '.actions', :default => t("helpers.actions") %></th>
        </tr>
      </thead>
      <tbody>
        <% @orders.each do |order| %>
          <tr>
            <td><%= link_to order.id, order_path(order) %></td>
            <td><%= order.drink %></td>
            <td><%= order.time %></td>
            <td><%= order.price %></td>
            <td><%= order.created_at %></td>
            <td>
          <%= link_to t('.edit', :default => t("helpers.links.edit")),
                      edit_order_path(order), :class => 'btn btn-mini' %>
          <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
                      order_path(order),
                      :method => :delete,
                      :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
                      :class => 'btn btn-mini btn-danger' %>


        </td>
      </tr>
    <% end %>
  </tbody>
</table>


<%= link_to t('.new', :default => t("helpers.links.new")), new_order_path, :class => 'btn btn-primary' %>

并且,控制器中的索引函数:

def index
  @orders = Order.all

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @orders }
  end
end

我找不到两个缺少的括号。我错过了什么吗?

4

2 回答 2

2

这里缺少一个:

<th><%= model_class.human_attribute_name(:drink %></th>

这有帮助吗?

于 2012-05-31T00:23:15.020 回答
0

在这种情况下,最好的办法是寻找它告诉你的错误

<th><%= model_class.human_attribute_name(:drink %></th>

应该

<th><%= model_class.human_attribute_name(:drink) %></th>
于 2012-05-31T00:22:11.900 回答