small medium large xlarge

Generic-user-small
26 Jan 2012, 01:54
Stephen E Riley (12 posts)

Just working through the book. When I make all the changes shown in Iteration A2, I get the following “dump” in addition to the 3 product listing:

[#<Product id: 2, title: "CoffeeScript", description: "<p>\n CoffeeScript is JavaScript done right. …", image_url: "cs.jpg", price: #<BigDecimal:7f87157d77d0,’0.36E2’,9(36)>, created_at: "2012-01-25 16:23:36", updated_at: "2012-01-25 16:23:36">, #<Product id: 3, title: "Programming Ruby 1.9", description: "<p>\n Ruby is the fastest growing and most ex…", image_url: "ruby.jpg", price: #<BigDecimal:7f87157d6588,’0.4995E2’,18(45)>, created_at: "2012-01-25 16:23:36", updated_at: "2012-01-25 16:23:36">, #<Product id: 4, title: "Rails Test Prescriptions", description: "<p>\n <em>Rails Test Prescriptions</em> is a …", image_url: "rtp.jpg", price: #<BigDecimal:7f87157d5430,’0.3495E2’,18(45)>, created_at: "2012-01-25 16:23:36", updated_at: "2012-01-25 16:23:36">]

Looking at the source for the page, this is inserted between the last </tr> and </table>… right where the <% end %> is located.

This is the products/index.html.erb I am using:

Listing products

<%= @products.each do |product| %> <%= image_tag(product.image_url, class: 'list_image') %>
<%= product.title %>
<%= truncate(strip_tags(product.description), length: 80) %>
<%= link_to 'Show', product %>
<%= link_to 'Edit', edit_product_path(product) %>
<%= link_to 'Destroy', product, confirm: 'Are you sure?', method: :delete %> <% end %>


<%= link_to ‘New Product’, new_product_path %>

Generic-user-small
26 Jan 2012, 01:56
Stephen E Riley (12 posts)

wasn’t aware about the constraint on length. Here is the listing for index.html.erb again

Listing products

<%= @products.each do |product| %> <%= image_tag(product.image_url, class: 'list_image') %>
<%= product.title %>
<%= truncate(strip_tags(product.description), length: 80) %>
<%= link_to 'Show', product %>
<%= link_to 'Edit', edit_product_path(product) %>
<%= link_to 'Destroy', product, confirm: 'Are you sure?', method: :delete %> <% end %>


<%= link_to ‘New Product’, new_product_path %>

Generic-user-small
26 Jan 2012, 01:57
Stephen E Riley (12 posts)

Obviously, I don’t know how to escape the source correctly. Sorry

Samr_small_pragsmall
26 Jan 2012, 03:20
Sam Ruby (634 posts)

Remove the “=” from the line that reads @products.each do.... If you include the equals, it will display the value of @products in addition to looping through each product.

Generic-user-small
23 Jun 2012, 15:55
kou chang (2 posts)

I’m on chapter 6 6.2 Iteration A2: Making prettier Listings.

My issue is this:

SyntaxError in Products#index

Showing d:/work/depot/app/views/products/index.html.erb where line #25 raised:

d:/work/depot/app/views/products/index.html.erb:25: syntax error, unexpected keyword_end, expecting ‘)’ ‘); end ^ d:/work/depot/app/views/products/index.html.erb:32: syntax error, unexpected keyword_ensure, expecting ‘)’ d:/work/depot/app/views/products/index.html.erb:34: syntax error, unexpected keyword_end, expecting ‘)’

Extracted source (around line #25):

22: <%= link_to ‘Destroy’, product, confirm: ‘Are you sure?’, method: :delete %> 23: </td> 24: </tr> 25: <% end %> 26: </table> 27: 28:

Here is my code:

Listing products

<% @products.each do |product| %> <%= image_tag(product.image_url, class: 'list_image') %>
<%= product.title %>
<%= truncate(strip_tags(product.descriptin), length: 80 %>
<%= link_to 'Show', product %>
<%= linkt_to 'Edit', edit_product_path(product) %>
<%= link_to 'Destroy', product, confirm: 'Are you sure?', method: :delete %> <% end %>


<%= link_to ‘New product’, new_product_path %>

Generic-user-small
23 Jun 2012, 15:59
kou chang (2 posts)

Hey Sam,

You should allow us to copy and paste our code as text and don’t do the mark-up.

That way we all know what the code is and makes searching for solution easier. After all, we are about coding.

Thanks Kou Chang

Dave_gnome_head_isolated_pragsmall
23 Jun 2012, 16:47
Dave Thomas (390 posts)

Down the bottom of the area where you edit the text, it says hw to include code using pre and code tags.

Here is my code:

<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.descriptin), length: 80 %></dd>
      </dl>
    </td>
    
 
    <td class="list_actions">
      <%= link_to 'Show', product %><br/>
      <%= linkt_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 %>

The problem is here:

` ~~~

<%= truncate(strip_tags(product.descriptin), length: 80 %></dd> ~~~ `

You’re missing a closing parenthesis. It looks like ‘description’ is also misspelled. Further down, you have ‘linkt_to’ as well.

You must be logged in to comment