wikipedia href=”http://en.wikipedia.org/wiki/Sam_Ruby”>http://en.wikipedia.org/wiki/Sam_Ruby

Web Site | Blog

Posts by Sam Ruby

27 Oct 2011, 15:59
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Compile error of your index.html.erb)

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 `': 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.

27 Oct 2011, 17:09
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Release date for 3.1 paper book ?)
27 Oct 2011, 18:56
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Compile error of your index.html.erb)

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.

28 Oct 2011, 16:57
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Bewildering rate of change)

As one of the authors, I can certainly empathize with this. :-)

I will, however, state that the Rails team works really hard to (for example) make sure that a working Rails 3.0 project will work on Rails 3.1. You can, again for example, leave your images in the public directory if you set config.assets.enabled = false. You also don’t need to take advantage of CoffeeScript, and can continue to use Prototype/Script.aculo.us.

What is true is that best practices are evolving rapidly. Additionally, the scaffolding generator changed drastically which caused the instructions in the 1st edition to be relatively useless (but the code previously generated would still mostly work). For Rails 3, a tool was created to help you with the specifics of an upgrade.

30 Oct 2011, 18:13
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Ch 7 Rake Task Exceptions (Rails 3.1, Ruby 1.9.2))

If I read that call stack correctly, you have two different versions of rake installed. What does gem list rake produce on your system?

Related reading:

http://forums.pragprog.com/forums/148/topics/95…

http://stackoverflow.com/questions/6181312/how-...

Offhand, I don’t know the answer to your bundle exec alias question, but I will say that I haven’t had to explicitly use bundle exec. But perhaps that’s because I only have one version of rake installed, and use rails server.

31 Oct 2011, 02:09
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Ch 7 Rake Task Exceptions (Rails 3.1, Ruby 1.9.2))

There probably are three real errors in your code some place, probably typos or the like. Without seeing your code, this is hard to diagnose (except for the second one!).

The first failure indicates that validation on urls is not taking place. Try creating a product using the web page with a URL of fred.doc and verify that you are getting the error you expect. The validation code that you are testing here should be in app/models/product.rb.

The second failure looks like a simple typo: il8n should be i18n.

The final failure is the opposite of the first: you are unable to create a product, presumably because of a validation failure. Look in test/functional/products_controller_test.rb for something wrong with the values that you are assigning to @update. Again, it might be helpful if you try entering these values using the web interface and verifying that you can create a product with these attributes.

11 Nov 2011, 17:01
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > assert_select in functional test)

Jeff: can you verify for me that you have updated your fixture?

http://media.pragprog.com/titles/rails4/code/ra…

The following is the output you should be seeing:

http://intertwingly.net/projects/AWDwR4/checkde…

As to RSpec and RCov, this book is about Rails and for better or worse Rails ships with test unit, so that’s what this book focuses on. If you want a book that focuses on testing, I suggest Rails Test Prescriptions: Keeping Your Application Healthy.

12 Nov 2011, 19:31
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Including application helpers in tests)

Long answer:

require 'rubygems'
require 'action_view'
require 'action_view/helpers'
require './app/helpers/application_helper'
include ApplicationHelper

Depending on what you put in your helper, you might be able to get away with less than that. Much less.

15 Nov 2011, 18:01
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Errors running tests, on page 68?)

Short answer: go into your Gemfile, modify the line that contains the ‘turn’ gem to look like this:

gem 'turn', '0.8.2', :require => false

Once that is complete, execute the following command:

bundle update

Longer answer: the turn gem (note this in the top of your exception traceback) has been updated to require a version of Minitest that is later than the version that Rails 3.1 supports. There is a version of Rails in beta now (3.1.2.rc-2) that pins down the exact version of the Turn gem in the way I specified above. The next version of Rails (3.2) will drop the Turn gem entirely—all it does is pretty print testing output.

Based on where you are in the book, I would suggest simply making the changes above and not worrying about it further; these topics will be covered later in the book, but for now your best best is to focus on learning Rails before branching out.

15 Nov 2011, 20:47
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > New b question - rails server)

What operating system are you using? If you are using Windows or Mac OSX, execjs is typically able to find a preinstalled runtime. If you are using Linux, the quickest way to get up and running is to install nodejs:

https://github.com/joyent/node/wiki/Installing-...
16 Nov 2011, 15:19
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > New b question - rails server)

Can you verify that ExecJS can find a runtime?

C:\Users\rubys\work\demo>ruby -r execjs -e "p ExecJS.runtime.name" 
"JScript"

People’s tastes in editor’s vary, but here’s a free editor that you can try: http://notepad-plus-plus.org/

16 Nov 2011, 22:05
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Including application helpers in tests)

currency not defined means that you have defined currency in a module that you haven’t included in your current scope, so the include statement addresses this. The next problem you will find is that number_to_currency is not defined, and that’s what the rest of the lines help with.

For more information, scan ahead to section 24.2. This information is at the bottom of that section.

16 Nov 2011, 22:30
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > New b question - rails server)

I’m not sure where the best place is to ask execjs support questions, but it does appear that one of the supported runtimes, namely node.js, now has a Windows installer:

http://nodejs.org/#download

I don’t have a Windows machine that does NOT have JScript (after all, it is a part of IE) to test out if Node.js is a viable alternative on windows to test this out in advance, but perhaps you can try it.

20 Nov 2011, 14:46
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Missing line_item price column)
Can someone please point me to where I can find this in book version 2.1?

First “Playtime” exercise at the end of chapter 10. These exercises are optional, but solutions to selected ones (including this one) are included in the downloadable code. You can find hints (as well as follow the link to the solution in this case) on the wiki:

http://pragprog.com/wikis/wiki/Task-E-ASmarterCart
20 Nov 2011, 20:14
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Missing line_item price column)

depot_n (and depot_r) have the migration that is used to add price to line item:

http://media.pragprog.com/titles/rails4/code/ra…

21 Nov 2011, 02:47
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Error installing 1.9.2)
21 Nov 2011, 18:56
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > assert_equal (newb))

Parenthesis are optional in method calls, so the above is exactly equivalent to

assert_equal( "must be greater than or equal to 0.01",
    product.errors[:price].join('; '), nil )
22 Nov 2011, 07:32
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > assert_equal (newb))
product.errors[:price] is an array of errors, after all, there may be multiple errors associated with that one field.

We could separately verify that the length of this array (and therefore the number of errors associated with this field) is exactly one AND that the first such error is the one that we are expecting, or we can simply concatenate all of the errors and verify that the result is what we are expecting.

assert product.invalid? is arguably redundant in this particular example, and certainly less precise than checking for a specific error message. It does have some minimal value in that it checks that there not only is a message, but that this field has been flagged as in error.

If no error message is passed, assert_equal will simply state the obvious when there is a failure, namely that expected is not equal to actual.

25 Nov 2011, 01:52
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > 11.6 Testing AJAX Changes "NoMethodError in Carts#index")

This suggests that @cart is an array, not a single cart. I would suggest taking a careful look at the index method in app/controllers/carts_controller.rb. Are you by any chance setting @cart (singular) instead of @carts (plural) in that method?

16 Dec 2011, 16:12
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Chapter 16 K1 - 403 Forbidden)

Admittedly a shot in the dark: possible file permission problem?

On Mac machines, the web server runs with the effective user id of _www. Make sure that your directories have both read and execute permissions set, and that your files have the read permission set.

$ ls -ld depot
drwxr-xr-x  18 rubys  staff  612 Jun 21 11:28 depot
24 Dec 2011, 15:49
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Chapter 6: products.css.scss?)

Thanks for the errata, it will be fixed in the next update.

28 Dec 2011, 12:58
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Add a dash of ajax)

E M: I use Firefox (and Firebug), but you might be able to do the same things with Safari’s Web Inspector has most of the same functionality.

Based on what you have described, the button did send a “remote” request to the server, and the server produced a response.

The first thing to verify (view-source will suffice) is that your page has an element with an id of cart:

<div id="cart" style="display: none">

Next, enable Tools => Web Developer => Web Console, and issue your request. If there are any JavaScript errors, they will show up in the console. The console will also show when a POST request is issued, and what the HTTP response is.

If this doesn’t show the problem, enable Tools => Web Developer => Firebug => Open Firebug. Click on the Net tab, then XHR. Now issue the request again. You should see a POST line show up in Firebug. Click on the +, then click on response. What you should see should look something like:

$('#cart').html("<div class=\"cart_title\">Your Cart<\/div>\n...<\/div>\n");
28 Dec 2011, 19:58
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > Add a dash of ajax)

First, I will assume that the “1 request” is on the next line? If that were to be a part of the response, you would get a JavaScript error.

Looking at the response itself, I see “smart” quotes in places – backtics instead of apostrophe’s around #cart, and the first and last double quote on the call to html is a close quote. I don’t know if this was a part of the response or was mangled by this forum software. But in any case, try doing this again, then select and copy the entire response to the clipboard. Then select the console tab. At the bottom of the screen you should see three greater than signs. Paste the response there then hit enter.

If the response is correct, it should update the cart. If not, you should see the error. If you press the up-arrow key you should be able to retrieve the text, edit it, and press enter again. Once you get it working, change the code on your server to produce the response that works.

06 Jan 2012, 11:07
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > rails 3.1 + haml)

HAML works for me, using the instructions provided in the book, with Rails 3.1:

http://intertwingly.net/projects/AWDwR4/checkde…

12 Jan 2012, 02:49
Samr_small_pragsmall

Sam Ruby (549 posts)

(from Agile Web Development with Rails 3.2 > rails 3.1 + haml)

549 posts