操作控制器:语法错误,缺少括号

时间:2012-05-31 00:19:41

标签: ruby-on-rails ruby-on-rails-3 twitter-bootstrap erb scaffolding

在我的rails应用程序中,仅使用scaffold生成的视图,再加上bootstrap,我收到一个Action Controller错误:

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

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

2 个答案:

答案 0 :(得分:2)

这里缺少一个:

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

有帮助吗?

答案 1 :(得分:0)

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

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

应该是

<th><%= model_class.human_attribute_name(:drink) %></th>
相关问题