Errata

Learning Rails 3

Errata for Learning Rails 3

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
PDF, Other Digital Version
Page xv
Rails Versions

This book was updated for Rails 3.2.3 and Rails 1.9.2.
should say
This book was updated for Rails 3.2.3 and Ruby 1.9.2.

Note from the Author or Editor:
Yes, this is definitely correct. That's Ruby 1.9.2.

Michael Simpson  May 24, 2012  Jul 26, 2013
ePub
Page xi
2nd paragraph

The Print ISBN:978-1-4493-0933-6 is there in the text:
"... database, mos9781449309336t of the time."

Note from the Author or Editor:
Definitely please remove the extra ISBN! I don't see it in my print copy, so I'm not sure what happened.

Anonymous  May 03, 2013  Jul 26, 2013
Printed
Page 13
Next to last paragraph

It says, "... and then look at http:// localhost:3000/hello, hello in the application." This is unclear as to what actually goes in the address bar.

Note from the Author or Editor:
Please delete "hello in the application".

Casey Borders  Jul 27, 2012  Jul 26, 2013
PDF
Page 22-23
Example 3-3

It seems that in Rails 3.1, stylesheets are no longer supposed to be placed in public/stylesheets. The new location now seems to be in /app/assets/stylesheets.

Note from the Author or Editor:
Thank you - you are correct, though it's actually even more complicated than that. The update to the early release will cover this shortly!

Anonymous  Sep 22, 2011  Jul 11, 2012
PDF
Page 28
The code after the sixth paragraph

The code in the PDF is written:

"
<%= stylesheet_link_tag 'hello', :media => "all", :type => "text/css", %>
"

That code produces an error. This is the correct code:

<%= stylesheet_link_tag 'hello', :media => "all", :type => "text/css" %>

Basically without the comma at the end.

Hope that helps.

:)

Note from the Author or Editor:
Yes, please delete the comma!

Paul  Feb 01, 2013  Jul 26, 2013
Printed
Page 29
Figure 3-3

Incorrect image. It shows a screenshot of the webpage. It should show how Rails decides which layout to show.

Note from the Author or Editor:
This figure should be replaced with Figure 3-4 of the original Learning Rails.

Casey Borders  Jul 27, 2012  Jul 26, 2013
PDF
Page 30
Example 3-9

The left angle and right angle brackets in the example were swapped. For example, one of the tags is misprinted as >!DOCTYPE html<

Note from the Author or Editor:
Argh. Completely right, and very embarassing. Fixed!

GiantMarshmallow  Sep 23, 2011  Jul 11, 2012
PDF
Page 35
2nd paragraph, last sentence

The line '<%= yield :name %>' should read ':list' not ':name', as the latter does not appear in Example 3-13.

Note from the Author or Editor:
This is correct. Please change 'yield :name' to 'yield :list'.

Jordan Yee  Apr 16, 2012  Jul 26, 2013
PDF
Page 49
Tip on top of the page, last line

Only "bundle exec" should be in constant width, as "run" is not part of the command...


[jiehan@jiehan-tpx300 testing]$ run bundle exec rake db:migrate
bash: run: command not found...
^C

Note from the Author or Editor:
Thanks! Fixed!

Jiehan Zheng  Jun 25, 2012  Jul 11, 2012
PDF
Page 52
find last - next paragraph

The find last description says the same thing as "find first" = 'will return the first matching value only'. Isn't that supposed to be the LAST matching value only? Otherwise how is this different than find first?

Note from the Author or Editor:
You're completely right. That should be:

"return the last matching value only".

Thank you!

Tim Chambers  Aug 15, 2012  Jul 26, 2013
Printed
Page 52
bottom page, 'where' section

The three examples for the 'where' method are shown with the 'all' keyword inserted, i.e.

Users.all.where("registered = true")
Users.all.where(:registered => true)
Users.all.where("email = ?", params[:email])

it looks like as of Rails 3 the 'all' should not be there, so examples should be:

Users.where("registered = true")
Users.where(:registered => true)
Users.where("email = ?", params[:email])

Note from the Author or Editor:
This is correct. We should delete .all in all three cases.

Curt Gardner  May 08, 2013  Jul 26, 2013
PDF
Page 62
The link inside the pink box

On page 62 of 468, the link to the "reserved words" does not work or is no longer valid. Please update. Thanks

Note from the Author or Editor:
On page 17, please replace the oldwiki link with http://bparanj.blogspot.com/2011/07/reserved-words-in-rails.html .

Anonymous  Feb 09, 2013  Jul 26, 2013
PDF
Page 69
Figure 5-6

This whole section is based on a "Person" model, but the figure references a "Student" model. Not hard to figure out, but a stupid mistake.

Note from the Author or Editor:
In the left hand column of Figure 5-6, please change all instances of 'student' to 'person' and 'students' to 'people'. Can also do the same in the third column.

Anonymous  Mar 01, 2012  Jul 26, 2013
PDF
Page 90
footnote

The url is wrong I believe:

1. From the API docs (http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html/).

should be:

1. From the API docs (http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html).

Need to change .com to .org and DROP the final "/".

Note from the Author or Editor:
Strange. I can see how the stray / got there, but the .com / .org switch is strange. This should be:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

Tim Chambers  Aug 15, 2012  Jul 26, 2013
PDF
Page 90, 91
Class attribute paragraph near bottom

The paragraph states:

This will produce a checkbox with a class attribute:
<input class="email" name="person[can_send_email]" type="hidden" value="0" /> <input id="person_can_send_email" name="person[can_send_email]" type="checkbox" value="1" />


However the "class=email" specification is on the hidden tag. It wouldn't be terribly useful except under bizarre JS conditions because it BELONGS ON THE input type-checkbox tag.

This same error is on the top of page 91 as well in that example.

Note from the Author or Editor:
This is correct - a copy/paste botch. Please move 'class="email"' to the input element in the line below in both cases.

Tim Chambers  Aug 15, 2012  Jul 26, 2013
PDF
Page 91-92
Example 6-4

Labels don't work because of prefix "person_" in Rails code.

Instead of:

<fieldset>
<legend>Country</legend>
<%= f.radio_button :country, 'USA' %> <%= f.label "person_country_usa", "USA" %><br />
<%= f.radio_button :country, 'Canada' %> <%= f.label "person_country_canada", "Canada" %><br />
<%= f.radio_button :country, 'Mexico' %> <%= f.label "person_country_mexico", "Mexico" %><br />
</fieldset>

<fieldset>
<legend>Country</legend>
<input id="person_country_usa" name="person[country]" type="radio" value="USA" />
<label for="person_person_country_usa">USA</label><br />
<input id="person_country_canada" name="person[country]" type="radio" value="Canada" />
<label for="person_person_country_canada">Canada</label><br />
<input id="person_country_mexico" name="person[country]" type="radio" value="Mexico" />
<label for="person_person_country_mexico">Mexico</label><br />
</fieldset>

it should be:

<fieldset>
<legend>Country</legend>
<%= f.radio_button :country, 'USA' %> <%= f.label "country_usa", "USA" %><br />
<%= f.radio_button :country, 'Canada' %> <%= f.label "country_canada", "Canada" %><br />
<%= f.radio_button :country, 'Mexico' %> <%= f.label "country_mexico", "Mexico" %><br />
</fieldset>

<fieldset>
<legend>Country</legend>
<input id="person_country_usa" name="person[country]" type="radio" value="USA" />
<label for="person_country_usa">USA</label><br />
<input id="person_country_canada" name="person[country]" type="radio" value="Canada" />
<label for="person_country_canada">Canada</label><br />
<input id="person_country_mexico" name="person[country]" type="radio" value="Mexico" />
<label for="person_country_mexico">Mexico</label><br />
</fieldset>

Note from the Author or Editor:
This is correct. Please change the code.

Anonymous  Aug 25, 2012  Jul 26, 2013
97
section Creating Helper Methods

"methods defined in people_helper.rb are only available to views that pertain to operations on the person model". Not so. First, naming of helpers relates to controllers, not to models. But, even more significant, there is *no* scoping of helpers; *all* helpers are visible to *all* views and *all* layouts!

This is kind of awful because it makes nonsense of the notion of different helper files; you may as well use application_helper.rb for everything and ignore the others. It looks like maybe what you're saying here was true in Rails 1, but it hasn't been true in a long time; universal visibility has been the case for some time, according to my research. (The note about precedence should probably be taken out too, unless you're sure about it; my research suggests that precedence is a muddle.)

Note from the Author or Editor:
Please delete from "Helper methods that are defined in...." through the note at the bottom of the page. Think this used to be true, but isn't now.

Matt Neuburg
Matt Neuburg
 
Sep 08, 2012  Jul 26, 2013
PDF
Page 111
2nd paragraph under "The Power of Declarative Validation"

I would suggest a small clarification that this validation code goes in person.rb, after attr_accessible and before "end"; it's not entirely clear from the current early release version. I had to look at the downloadable source to confirm that's where it's supposed to go.

Note from the Author or Editor:
Thank you - I just added it!

Anonymous  Jul 01, 2012  Jul 11, 2012
PDF
Page 111
Note about other resources re: regular expressions

You note:

Regular expressions are a complex subject you can study to nearly infinite depth. Appendix C can get you started. Jeffrey Friedl?s Mastering Regular Expressions (O?Reilly, 2006) is pretty much the classic overview of the field, but Tony Stubblebine?s Regular Expression Pocket Refer- ence (O?Reilly, 2007) is a concise guide to the capabilities and syntax in different environments.

----


You should also note the new book Introducing Regular Expressions by Michael Fitzgerald - July 2012 - available at O'Reilly is IMO a very good and current reference and a great intro. I have no affiliation, but it is a fresh book and more current.

Note from the Author or Editor:
Yes, we should add that. It wasn't available at the time I was writing, though I was editing it and definitely like it!

Tim Chambers  Aug 15, 2012  Jul 26, 2013
Printed
Page 134
Integrating Form Builder Styles

The path for wrapping_tidy_form_builder is said to be app/views/wrapping_tidy_form_builder.rb this should be app/helpers/wrapping_tidy_form_builder.rb as it is in the example code

Note from the Author or Editor:
Yes, please change the path as suggested.

Stefaan Verscheure  Feb 09, 2013  Jul 26, 2013
PDF
Page 152
Last line of the page

The URL that it links to "http://blog.hasmanythrough.com/2007/7/14/validate-your-existence" is no longer valid.

Note from the Author or Editor:
Argh. That's sad. Changing the prose to lose the reference.

Jiehan Zheng  Jul 06, 2012  Jul 11, 2012
PDF
Page 153
First code sample

The text says:

Near the top of the config/routes.rb file are the lines:
map.resources :awards
map.resources :students
Delete them, and replace them with:
map.resources :students, :has_many => [ :awards ]

the generated files that rails produced say:

resources :awards
resources :students

There is no reference to a map object.

I'm using:

$ rails -v
3.0.3

$ ruby -v
ruby 1.8.7 (20011-06-30 patchlevel 352) [i686-linux]

If I replace the lines with
resources :students, :has_many => [ :awards ]

then the exception

undefined local variable or method 'map' for #<ActionDispatch::Routing::Mapper:0xb75cdffc>

goes away and the URL localhost:3000/students/1
starts working. So this seems like a typo.

For some reason localhost:3000/students/1/awards/1 still isn't working. That's probably not a problem with the text.

Note from the Author or Editor:
Sorry - this was a shift from version 2 to version 3 that got by us for this chapter at the time. Fixed now.

Russell Owen  Oct 31, 2011  Jul 11, 2012
PDF, Other Digital Version
Page 160
Example 9-3, line 2

Example 9-3 has
<% if !@student.awards.empty? > 0 %>
which didn't work until I omitted the "> 0" e.g.
<% if !@student.awards.empty? %>

Note from the Author or Editor:
This is correct - we need to strike the >0.

rjr20  Jul 08, 2012  Jul 11, 2012
PDF
Page 191
First paragraph below the example

The second half of the sentence:
"The second argument is the name of the column, and the third column is the type."

Should be:
"...and the third *argument* is the type." :)

Note from the Author or Editor:
This is on 207 of the current PDF. Please change "third column" to "third argument".

Jiehan Zheng  Jul 12, 2012  Jul 26, 2013
PDF
Page 192
First code example

The second to last "end" matches "def change," therefore it should have two spaces of indentation to the left of it.

Note from the Author or Editor:
This is on 184 of the current PDF. Please insert two spaces before the first end in:

end
end

to make it:

end
end

Jiehan Zheng  Jul 12, 2012  Jul 26, 2013
Printed
Page 239
Stories Identities, code

class Identity < OmniAuth::Identity::Models::ActiveRecord
attr_accessible :email, :name, :password_digest :password,
:password confirmation
end

There is a missing comma after password_digest, and an underscore missing from password_confirmation. it seems and it should be this:

class Identity < OmniAuth::Identity::Models::ActiveRecord
attr_accessible :email, :name, :password_digest, :password,
:password_confirmation
end

(submitted by Mike Lyons)

Simon St. Laurent
Simon St. Laurent
 
Oct 08, 2012  Jul 26, 2013
Printed
Page 239
2nd paragraph

"..the class it inherits fron." should be "..the class it inherits from."

Note from the Author or Editor:
Yes, it's in the 2nd paragraph. Please make "fron" into "from".

Scott Glass  Oct 14, 2012  Jul 26, 2013
PDF
Page 243
2nd line under Figure 13-10

"Unles" should be "Unless" maybe?

Note from the Author or Editor:
On page 243 (PDF), line 2 in para under Figure 13-10, please change "Unles" to "Unless"

Jiehan Zheng  Jul 15, 2012  Jul 26, 2013
Printed
Page 259
near bottom

This code example:

match 'this/uri/exactly' :controller => "myController", :action => "myAction"

Doesn't there need to be a comma after 'this/uri/exactly', to separate the first argument to the match method from the hash that follows? Otherwise I don't understand the syntax.

Top of next page, 260 --

match 'this/uri/exactly', => myController#myAction

Now there is a comma after the first argument but then there appears to be a hash with no key. Is that right? Also, what kind of object is myController#myAction? Not in quotes so I guess its not a string.

Note from the Author or Editor:
There should be a comma between "match 'this/uri/exactly'" and ":controller"

Loran  Mar 06, 2013  Jul 26, 2013
Printed
Page 299
2nd paragraph

Not sure how to classify the error, but the sample code for chapter 18 is not available from the book's website and the reference reads "ch18/students/0Y".

Note from the Author or Editor:
Fixed in download file.

Anonymous  Aug 14, 2012 
PDF
Page 318
1st paragraph

'rails testbed' command should be
'rails new testbed'

Note from the Author or Editor:
318 in the PDF, 320 in print. Yes, 'rails testbed' should be 'rails new testbed'.

Anonymous  Aug 26, 2012  Jul 26, 2013
Other Digital Version
1634
Example 4-2, Example 4-7

Example 4-2 has
<h1>Hello <%= @name %></h1>
while Example 4-7
<h1>Hello <%=h @name %></h1>
What does <%=h mean?
(NB I entered the kindle location number in the page number box above because I don't have the page number, sorry if that causes any trouble.)

Note from the Author or Editor:
The h was from an older version of Rails. It doesn't break anything, but I've taken all of them out.

RebeccaR  Jul 05, 2012  Jul 11, 2012