-1

In my rails app, using only the scaffold generated view, plus bootstrap, I'm getting an Action Controller error:

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'

Here's the 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' %>

And, the index function in the controller:

def index
  @orders = Order.all

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

I could not find the two missing parentheses. Am I missing something?

MichaelFine
  • 121
  • 1
  • 6

2 Answers2

2

there's one missing from here:

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

does that help?

Matenia Rossides
  • 1,406
  • 9
  • 35
0

In this case, the best thing to do is look for what it's telling you is wrong

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

Should be

<th><%= model_class.human_attribute_name(:drink) %></th>
DVG
  • 17,392
  • 7
  • 61
  • 88