开发者

Don't understand this Rails error message

开发者 https://www.devze.com 2023-04-08 11:05 出处:网络
I\'m using code downloaded from a book called Agile Web Development with Rails 4th edition. It provides code for Rails 3.05 and Rails 3.1. I\'m using开发者_Python百科 the latter... I don\'t understand

I'm using code downloaded from a book called Agile Web Development with Rails 4th edition. It provides code for Rails 3.05 and Rails 3.1. I'm using开发者_Python百科 the latter... I don't understand the error message it produced when I tried to load it in the server.

I'd be grateful if you can explain for a newbie..

This is the index created for the Product

<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 %>

This is the error message

SyntaxError in Products#index

Showing /Users/michaeljohnmitchell/Sites/peep/app/views/products/index.html.erb where line #15 raised:

compile error
/Users/michaeljohnmitchell/Sites/peep/app/views/products/index.html.erb:15: 
syntax error, unexpected ':', expecting ')'
               length: 80) );@output_buffer.safe_concat('</dd>
                      ^
/Users/michaeljohnmitchell/Sites/peep/app/views/products/index.html.erb:23: 
syntax error, unexpected ':', expecting ')'
                  confirm: 'Are you sure?',
                          ^
/Users/michaeljohnmitchell/Sites/peep/app/views/products/index.html.erb:23: 
syntax error, unexpected ',', expecting ')'
Extracted source (around line #15):

12:       <dl>
13:         <dt><%= product.title %></dt>
14:         <dd><%= truncate(strip_tags(product.description),
15:                length: 80) %></dd>
16:       </dl>
17:     </td>
18: 
Trace of template inclusion: app/views/products/index.html.erb

Rails.root: /Users/michaeljohnmitchell/Sites/peep

Application Trace | Framework Trace | Full Trace
app/views/products/index.html.erb:36:in `compile'
app/controllers/products_controller.rb:7:in `index'


Try using a ruby 1.8-style hash literal:

<%= image_tag(product.image_url, :class => 'list_image') %>

UPDATE: Since you are using ruby 1.8.7, not 1.9, all your hashes have to be in this format:

<%= image_tag(product.image_url, :class => 'list_image') %>
<%= truncate(strip_tags(product.description), :length => 80) %>
<%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %>

Plus any other hashes you us in the future.


The options must be an hash for image_tag @ http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag

<%= image_tag(product.image_url, :class => 'list_image') %>
0

精彩评论

暂无评论...
验证码 换一张
取 消