small medium large xlarge

Generic-user-small
27 Oct 2011, 15:02
David Bone (5 posts)

Question: How to keep going with your book’s learning ruby-on-rails sessions? Running on mac Lion: Software Mac OS X Lion 10.7.1 (11B26) Ruby: davids-MacBook-Pro:products bone_david$ irb -v irb 0.9.5(05/04/13)

P. 92 the index.html.erb when compiled produces this error: davids-MacBook-Pro:products bone_david$ erb index.html.erb index.html.erb:32: compile error (SyntaxError) index.html.erb:7: syntax error, unexpected ‘:’ …_tag(product.image_url, class: ‘list_image’) ).to_s); _erbou… ^ index.html.erb:7: syntax error, unexpected ‘)’, expecting kEND …, class: ‘list_image’) ).to_s); _erbout.concat “\n” ^ index.html.erb:13: syntax error, unexpected ‘:’, expecting ‘)’ …s(product.description),length: 80) ).to_s); _erbout.concat “… ^ index.html.erb:13: syntax error, unexpected ‘)’, expecting kEND …scription),length: 80) ).to_s); _erbout.concat “</dd>\n” ^ index.html.erb:22: syntax error, unexpected ‘:’, expecting ‘)’ confirm: ‘Are you sure?’, ^ index.html.erb:22: syntax error, unexpected ‘,’, expecting ‘)’ davids-MacBook-Pro:products bone_david$

Here is the file: davids-MacBook-Pro:products bone_david$ cat index.html.erb

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 %> davids-MacBook-Pro:products bone_david$

I’m new to Ruby/rails etc and teaching myself by your books. Any help to continue is appreciated. Thank u for your eyes/ears and advice Dave

Samr_small_pragsmall
27 Oct 2011, 15:59
Sam Ruby (634 posts)

You will get that error if you are running ruby 1.8.7. Type ruby -v to see which version of Ruby you are running. If you installed ruby 1.9.2 via rvm, try entering rvm 1.9.2 in your Terminal window, and running the erb command again. If you do so, you should now see:

index.html.erb:4:in `<main>': undefined method `each' for nil:NilClass (NoMethodError)

… which is to be expected as you are running erb without having first set the value of @products.

Generic-user-small
27 Oct 2011, 17:56
David Bone (5 posts)

Sam, Thks for the reply my ruby is: ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

So should i try to install ruby 1.9.2?

Will this correct the problem as i’m just following the book’s steps or will i get the undefined method problem in your reply after the install 1.9.2? If so the … which is to be expected as you are running erb without having first set the value of @products. (the error showed up when running the server with the new code in index.html.erb. this is why i just tried to compile with erb) seems that the book’s steps in learning rails needs some more advice as i’m still learning to become familiar with ruby/rails. dave Dave

Samr_small_pragsmall
27 Oct 2011, 18:56
Sam Ruby (634 posts)

For the ruby version question, take a look at the “Choosing a Ruby version” sidebar on the second page of chapter 1. Also be aware that there are plans to stop supporting Ruby 1.8.7 starting late next year. So, yes, if you are new to this, you really should be starting with Ruby 1.9.2. As you are a Mac user, you can find instructions in section 1.2.

The index method in app/controllers/products_controller.rb should be setting the @products variable, and so you should not be seeing a message about an undefined method. The only reason you should be seeing that is if you are running erb directly without having first set this value.

I would recommend that you either install Ruby 1.9.2, or be prepared to convert all of the examples to the Ruby 1.8.7 syntax, before debugging this further.

Generic-user-small
27 Oct 2011, 20:40
David Bone (5 posts)

Sam, i’ll install the newer version and see where it takes me. thk u for the fast response and the directions bring my system up to date. dave

You must be logged in to comment