By Developers, For Developers

Historical errata for Agile Web Development with Rails 4

PDF PgPaper PgTypeDescriptionFixed onComments
148131OK

Iteration E3: Finishing the Cart • 131, or 148 of 451 on the PDF:

It says “.total_line .total_cell” instead of “.total_line, .total_cell” (missing a comma) on the CSS block.

2013-05-06.total_line .total_cell (separated by spaces) means to select any element with a class of total_cell that is enclosed by an element with a class of total_line.
27SUGGEST

The first example with time:
It is now <%= @time %>
displays local time (I´m in Germany)

The second one:
Time in one hour: <%= 1.hour.from_now %>
displays UTC Time

It’ s puzzling for a beginner … IMHO you should change this using UTC or local time for both

2013-05-06
0SUGGEST

This issue happens only with Kindle format of the book. When code listing is too wide, right part of it is cropped. Example is at location 5203 (of 13882). Maybe there’s a way to wrap too long lines?

0TYPO

Kindle version, location 5442 (of 13882):
“We added a bit of CoffeScript in order to…”

Should be “CoffeeScript” instead.

2013-05-09
589TYPO

It says:
“A place for Static Web Pages
Thepublic directory…”

There should be an space between “the” and “public”.

2013-05-10
247TYPO

in the 6th paragraph starting with “From the output…” there is a command mentioned that reads " load ‘deploy assets’ ".

I think, this should be " load ‘deploy/assets’ " with the slash between it?

2013-05-10
247OK

On the second last line there is the URL for the repo access, which is constructed out of various variables that have been set before. I was confused about the fact that the repo access user seems to be the same user as the deployment machine access user.

This is so, because some pages before you set up the git repo on the machine with this user. A lot of people will be using other git repo machines. Maybe you could explain the assembly of the second last line on the page a bit more.

Or bring to users in the script… :deploy_user and :git_user ?

2013-06-12This is a tough one. I'm trying to keep the scenario simple and not overwhelm readers with options. Not everybody will be using git on other machines, and even those that do may not have a different user id on each machine. I'd rather not try to attempt to describe all possible configurations, but rather describe one that readers can get to work and then tailor as necessary.
257245OK

Shouldn’t the 4th command on the page create a RSA key instead of a DSA key?

There is " test -e ~/.ssh/id_dsa.pub || ssh-keygen -t dsa "
I think it should be " test -e ~/.ssh/id_dsa.pub || ssh-keygen -t rsa "

At least my config attempts with gitolite told me to use an RSA key…

2013-05-10http://www.linuxquestions.org/questions/linux-security-4/which-is-better-rsa-or-dsa-public-key-12593/
141SUGGEST

Beneath Figure 16, possibly reword: “This reveals way too much information about our application. It also seems fairly unprofessional.”

These comments seem misleading in context with the mention of security since a production app won’t display this much information.

2013-06-12
83TYPO

Text mentions “rails test models”, but example shows “rake test:models” (see bottom of page)

2013-05-17
656ERROR

The method Hash#diff is no longer used inside of Rails 4, and is being deprecated with no replacement.

2013-06-12
20TYPO

In paragraph one, line number 4, “That command added seven files” — I think the “seven” should be several.

2013-06-12
94OK

In building the store catalog page, I saw that after I had typed in the HTML/SCSS as described on pages 93-95, the catalog page did not format correctly. There was a style for a

tag in the SCSS, but not mentioned in the markup shown at the bottom of page 93 and the top of 94. It appears that there should be a

tag surrounding “<%= sanitize(product.description) %>” at the top of page 94. Adding that tag makes the layout behave properly. I have a feeling that this is a typo and not a technical error, as the screenshots seem properly formatted and the author simply forgot to transcribe a paragraph tag.

2013-06-12Note that's a "p, " which means "paragraph or". \n \nThe content, which is added in the next iteration, has paragraph tags embedded in it.
115OK

In the first paragraph on line 3, “…trivial template (we’ll tart it up in a minute):…”, “tart” should “start” — Karey Powell

2013-05-23
115OK

In the first paragraph on line 3, “…trivial template (we’ll tart it up in a minute):…”, “tart” should “start”

2013-05-23
324TYPO

Having the `DO NOT DO THIS` comment on one page and the rest of the code block on the next page (across a page turn no less) is probably ineffective.

2013-09-04New layout puts the comment on the same page as the code.
184TYPO

Missing end of sentence: “We start by creating a new Order object and initialize it from…” (the customer’s details / order params?)

2013-06-12
7ERROR

$ sudo rvm requirements —autolibs=enable
sudo: rvm: command not found

Apparently, sudo is useless, and the following command should suffice:
$ rvm requirements —autolibs=enable

2013-06-12
72OK

in the sample erb file(hxxp://media.pragprog.com/titles/rails4/code/rails40/depot_a/app/views/products/index.html.erb), you are not providing any div with classname products, so the corresponding products.css file won’t work as expected. The cycle odd, even css won’t work.

2013-06-12class is on the body tag: http://media.pragprog.com/titles/rails4/code/rails40/depot_d/app/views/layouts/application.html.erb \n \nThis was established in iteration a2, page 71
336ERROR

There is no more rake db:sessions:create. active record store has been extracted to a gem and need to run rails generate active_record:session_migration.

2013-06-12
109OK

the index.json.jbuilder for carts seems to be broken, after this update to the model, you may need to add json.extract! cart, :line_items

2013-06-12too early in the book to cover json
94SUGGEST

The paragraph before the styles store.css.scss talks about all pages created by the StoreController will create an HTML class of :store. My suggestion is to make a point of mentioning/reminding folks to look in view/store/layouts/application.html.erb and more specifically at the class for the HTML body tag.

2013-06-12
146ERROR

At the end of the page it describes adding “require jquery-ui” to app/assets/javascripts/application.js but this breaks as Rails displays and error about not finding the jquery-ui file. It appears that the gem ‘jquery-rails’ in the Gemfile includes jQuery’s ui by default and hence we don’t add “require jquery-ui” at all. When I removed “require jquery-ui” from app/assets/javascripts/application.js the app worked as it should.

2013-06-12
113OK

Existing text…
There’s a missing subdirectory ‘concerns’ in the book text according to my version of Rails 4.0.0.rc1.

“Your updated Product model should look like this:
rails40/depot_b/app/models/product.rb”

Change to…
“Your updated Product model should look like this:
rails40/depot_b/app/models/concerns/product.rb”

2013-06-12models go into the models directory. Concerns are for code shared between models.
22TYPO

Code example
rails40/demo3/app/views/say/hello.html.erb
is being split midway by “Making Development Easier” box.

2013-09-04fixed with new layout
26TYPO

Example rails40/demo5/app/views/say/goodbye.html.erb is split midway by Figure 3.

2013-09-04fixed with new layout
150OK

In the file views/line_items/create.js.erb when I use the value 0 instead of 1000 in jQuery’s show() method the item displays in the cart correctly. When I use 1000 I found that an empty cart will open but the newly added item is not displayed and instead the total is displayed as $0.

2013-06-12Can't reproduce
116OK

Rails 4.0.0.rc1 is not generating ~/test/models/product_test.rb mentioned in the text:

“Let’s see what kind of test goodies Rails generated inside test/models/product_test.rb when we generated that model:”

There is only one test file named test_helper.rb generated. Readers will need to create the file in order to follow along.

Checked github for a bug report in Rails 4.0.0.rc1 but I am not agile enough yet to be sure there isn’t one.

2013-06-12Per #51841
116OK

Disregard #51840 due to operator error.

2013-06-12
265TYPO

Figure 42 doesn’t render fully / text cut off (Preview on OS X 10.8)

2013-09-04Fixed image bounding box.
269ERROR

The link in footnote number 4 for Available Generators is broken. The page no longer exists. I performed a quick google search and it looks as though that page hasn’t been around for a few years (http[colon]//stackoverflow.com/questions/656294/where-are-the-downloadable-rails-generators). I wouldn’t know where to go for anything similar now as I look at rubyonrails.org

2013-06-12
149ERROR

After I added the AJAX to animate the bg color of line item, I ran into an error on localhost:3000, saying it couldn’t find jquery-ui.

To fix it, I updated my gemfile to change jquery to a fixed, older version: ‘gem ’jquery-rails’, ‘<3.0.0’’ and it worked again.

I think the newer jquery gem doesn’t include the ui package?

2013-06-13
xiTYPO

“This has lead to a number of substantial updates”

should read

“This has led to a number of substantial updates”

2013-06-17
180OK

config.action_mailer.delivery_method = :smtp | :sendmail | :test
doesnt work should be
config.action_mailer.delivery_method = :smtp, :sendmail, :test

2013-06-24The intent is that you pick one of the options.
9TYPO

Under the change log entry for printing B4.0 it says “an errata”. This should of course read “an erratum”.

2013-06-26
11ERROR

The Gemfile still references 4.0.0.rc2

2013-06-26
358ERROR

link_to’s confirm option was moved into the data attributes: data: { confirm: ‘x’ }

2013-07-12
326SUGGEST

In the description of the various render options there is one missing:

render(file: ‘dir/template’)

2013-07-12
368SUGGEST

It seems to work better if the filename at the top of the page is:
…/partial/_list.html.erb
instead of:
…/partial/list.html.erb

2013-07-12
368ERROR

<%= render(“shared/header”, title: article.title) %> should be <%= render("shared/header", object: article.title) %>

2013-07-12Changed to locals: {title: @article.title}
123OK

It appears that Rails 4 includes a new feature that throws an exception when there are pending migrations. This can be configured by setting config.active_record.migration.

New Rails 4 applications set this to :page_load by default, which means that when rake db:rollback is run as suggested on page 122-123, the next page load will show an ActiveRecord::PendingMigrationError stating “Migrations are pending; run ‘rake db:migrate RAILS_ENV=development’ to resolve this issue.”

This behavior can be toned down by setting config.active_record.migration to :app_load or turned off by removing the line. It can be confusing to inexperienced Rails developers why this error appears but is not mentioned in the text, so I’d recommend making a small note of it in the text.

2013-07-12or by moving the migration to another directory, as suggested by the text in the book.
208ERROR

Second line of “User.create(…)” input should also be colored.

2013-07-12
90TYPO

In the first text line of the page,
[…] make sure that that the timestamp […]
two “that”`s is one too much.

2013-07-12
120OK

I was confused by the code for the app/models/cart.rb example.

The beginning of the file should have:
class Cart < ActiveRecord::Base
has_many :line_items, dependent: :destroy

end

This is removed from the example and I wasn’t sure exactly where to put the updated code from the book. In previous examples this header code is always in the example.

2013-07-12Clicking on the link provides the whole source file. There are many cases in the book where self-contained excerpts are shown instead of the whole file.
211TYPO

In the fourth Playtime exercise:

The url for the curl command should probably end in “who_bought.atom” rather than “who_bought.xml”. Above the command it says “Test that it works by accessing an Atom feed:”, and in addition there would be no XML view unless the reader did the first Ch12 (Task G) Playtime exercise on page 177.

2013-07-12
215SUGGEST

Start of the last paragraph: “To do this…”
To do what?

2013-07-12
217TYPO

Paragraph on page 215 repeated:
“With this in place, we can see the results in Figure 30, English version of the front page, on page 216.”

2013-07-12
219205TYPO

The before_action() line causes the authorization() to be invoked before every action in our application.

Here, the “authorization” should be “authorize”

2013-07-12
71OK

The code provided in the book for app/views/layouts/application.html.erb appears to be the default code generated by rails, without the changes needed to make alternating row highlighting work in the depot app. The linked downloadable code has the correct code. Going through the depot tutorial only copying by hand from the book results in a depot app that does not do alternating row highlighting. Copying the downloadable files does work.

2013-07-12There is one line changed, which is the body element, highlighted by a triangle.
176OK

the _cart.html isn’t updated with the <% unless ….%> part

2013-07-23I don't understand this comment or can't reproduce the problem.
187SUGGEST

using single quotes for $("#notice#).hide(); would be more uniformed with the rest of the code that uses single quotes

2013-07-23
71OK

didn’t work

But when I change it for:

worked =)

2013-07-23works for me
5029ERROR

It says “This list will be accessible via the model, but it will be a view that accesses the list from the model and formats it for the end user.”

It probably should say “..it will NOT be a view..” (as that’s the role of the Controller). Or, maybe it’s correct as-is, but it could be read to imply that the view is accessing data directly from the model..

2013-07-23
116OK

Missing the line “line_item.product = product" in the controller. Add after the line "line_item = @cart.add_product(product.id)”

2013-07-23add_product does that
125TYPO

Footnote ‘2’ link bellow page giving 404 not found error:

guides.rubyonrails.org/debugging_rails_applications.html%23the-logger

Frank, thank you for alerting us about this. We're trying to reproduce the problem - could you please let us know what PDF viewer you're using and what method you are using for accessing the page? (I.e., are you clicking on the link, or copying and pasting it in the browser?) - Susannah Pfalzer, editor
127TYPO

Footnote ‘3’ link bellow page giving 404 not found error:

github.com/rails/strong_parameters%23readme

xiTYPO

In the first sentence of the third paragraph there’s a missing “at” between the words “only” and “what” at the end of the second line and beginning of the third line: “…tell you not only at what point…”

2013-08-12
126TYPO

“Instead of returning an array of results it either returns an existing LineItem or a new one.”

What does this sentence refer to? Seems to be a mix between “find_by” and “add_product”?

2013-08-12Meant to refer to find_by, as this is the first use of this method. Changed to say returns an existing LineItem or nil.
66TYPO

“Windows users will need to use dir/w instead of ls p." there is no space between ”dir" and “/w”

2013-08-12
128OK

Can’t mass-assign protected attributes for LineItem: product_id

Needed to add attr_accesible to app/models/line_item.rb

2013-08-12this book is for rails 4: mass-assignment checking was added in 3.2.3 and later removed from rails 4
119OK

before_action set_line_item is in line_items_controller but there is no method definition in the book. Had to add it to the bottom of the controller

2013-08-12Automatically generated by rails 4
73TYPO

Fourth paragraph, third sentence: “…it will raise and exception…” should be “an” exception

2013-08-12
77TYPO

Last sentence of the fourth paragraph ends: “…the resulting product listing might look something like the following:” but there’s no browser screenshot before the next paragraph.

2013-08-12
153TYPO

$ bundle install

After this command completes, restart your server.

Now that we have the [gem] available to our application, we need to …

2013-08-12
73TYPO

It reads “raise and exception” rather than “raise an exception”

Note also that because it uses Rails’ create!() method, it will raise and exception if records cannot be inserted because of validation errors.)

2013-08-12
119TYPO

There are repeating “that’s” in “Now that we know that that the value of @cart is set to the value of the current”

2013-08-12
125OK

Reads “While that was as part of” instead of “While that was a part of”.

“While that was as part of creating the initial scaffolding for a model, the basic approach is the same.”

2013-08-12
191ERROR

Trivial, but you need to sanitize line_item.product.title in _line_item.text.erb. Buy “Programming Ruby 1.9 & 2.0” and you’ll see why!

98OK

Product description overwrites image unless I put it in

tags.

<%= sanitize(product.description) %>

2014-07-09I can't reproduce this problem
4SUGGEST

The section on installing on Windows suggests that the simplest way to set up the Rails stack is to use railsinstaller.org

I have just talked a client through setting up under windows and I have to say that railsinstaller is out of date regarding the versions of ruby and rails available, indeed you even mention this stating “At the time of this writing, the latest version of RailsInstaller is version
2.2.1, which includes Ruby 1.9.3 and Rails 3.2. Until a new version is released
that supports Rails 4.0.0 or Ruby 2.0, feel free to use version 2.1 of RailsIn-
staller to get you started.”

Having visited rubyonrails.org/download I found the instructions for Windows installation to be quite different suggesting the use of rubyinstaller.org/
I found this solution to be painless and ended up with totally up to date Rails stack. I would like to suggest that the documentation is updated to use this process instead.

2014-07-08
43OK

On page 41 in “Ruby Names” you mention that a name prefixed with a colon is a symbol (e.g. :symbol).
On page 43 in “Arrays and Hashes” you mention that ‘:cello’ is a key and a little bit later that ‘cello:’ is a symbol.

Doesn’t this kind of contradict one another?
Or maybe explain somewhere, why this is the way it is.

Thanks
Tobias Beitz

2014-07-08A symbol may be a key; from the text of the book: "The use of symbols as hash keys is so commonplace that starting with Ruby 1.9 there is a special syntax for it, saving both keystrokes and eyestrain."
98OK

sanitize(product.description) removes any html tags and hence it will never be nicely printed “to make the descriptions more interesting for our customers”.
To allow html tags to be printed on page and make the description appear with rich text, on has to do product.description.html_safe instead.

2014-07-09sanitize only removes unsafe html tags
2125ERROR

On kindle at location 2125, the link that points to “configuring a database” section of guides.rubyonrails.org is pointing to the wrong place. I beliave that the right link is guides.rubyonrails.org/configuring.html#configuring-a-database.

116SUGGEST

Improve the implementation of “ensure_not_referenced_by_any_line_item” method. Since it does not follow the standard Ruby conventions. For example, “return” statements should be removed. This is a better alternative:

def ensure_not_referenced_by_any_line_item
unless line_items.empty?
errors.add :base, ‘Line Items Present’
return false
end
end

On the other hand, adding errors on a “before_….” callback does not render the object invalid. So, I do not think this is the correct approach here.

A better alternative is to raise a StandardError with a custom message.

2014-07-09
73ERROR

The margin comment on the right side indicates more information about “download” can be found “on page x”. Clicking on ‘x’ takes you to page x.

2013-09-04Link points to page xvi, where the subject is discussed.
274TYPO

Left margin note for “on page 53” doesn’t mention what it is referring to.

2013-09-04Added the content for the target.
166SUGGEST

In the paragraph beginning “Not surprisingly” you mention “our existing .js.erb template”. It might better be phrase “our existing create.js.erb template” to add context early. Nothing major and I know you mention the create template in the next sentence, but I tend to try to read sentence to sentence so I don’t miss anything. Just a suggestion.

2014-07-09
271TYPO

Words on the right side of figure 53 are getting cut off.

2013-09-04Fixed image bounding box.
112SUGGEST

The controller/concerns folder, introduced on page 112…I don’t think there was any meaningful description about it prior two this page. It’s just there!

What is it? Does it exist just to share information between controllers? Also, page 112 has a side note referencing the concept of “private” back on page 47. “private” on page 47 refers to access to methods in the same “INSTANCE”. How does this relate to the “concerns” folder?

10086TYPO

“Document not found” for MiniTest1 framework URL

2014-07-09
86TYPO

Link in footer to Mini Test in rdoc is broken, remove /unit and the link works.

2014-07-09
76OK

In the /index.html.erb file, the list_description class needs to be added to the

tag not the

tag. As it stands, the css is not being applied as intended to the table rows and the Show/Edit/Destroy links.

Medal!!!

Nick :)
n.bulmer@live.co.uk

2014-07-09The list_description class is meant to cover the description; the Show/Edit/Destroy links are covered by the list_actions class.
381ERROR

In the first line in the list the ‘object’ and ‘blob’ seem to be out of place. Adding cell borders might be a good idea to improve readablity.

153OK

11.4 Iteration F4

code has not specific location

2014-07-09That code demonstrates a potential approach. The actual changes which are made identify the specific location.
112SUGGEST

Please discuss the creation of a new file and the purpose of the controller/concerns folder. Nothing says outright that “we are going to create a new file in the concern folder for..” and it would be nice to have an explanation.

118TYPO

In the tenth-eleventh line from bottom, there is a space between “command” word and period sign:
“… automatically by the scaffold command . This method…”

This causes the period to stay alone at the beginning of new line.

2014-07-09
108SUGGEST

There is no introduction or explanation as to the purpose of controllers/concerns. It appears without hardly any context. What is a concern used for? Why doesn’t the author state that we are making a “concern.” These are VERY important questions that need to be answered since this seems to be a new feature in Rails 4.

125OK

I am reading a book P2.2 from 2012 and studying Rails4. I found a typo in the examples data from media.pragprog.com/titles/rails4/code/rails4-code.zip: there is a file at /rails%20code/rails40/depot_i/test/models/cart_test.rb, it contains a unknown variable book_one on line 27, and tests fail. It should be replaced with ruby_book.
Thanks.

2014-07-09http://media.pragprog.com/titles/rails4/code/rails40/depot_i/test/models/cart_test.rb \n \nI see two tests. The first defines and uses book_one and book_two. The second defines and uses ruby_book.
82TYPO

The link to the MiniTest docs at the bottom of the page is broken.

2014-07-09
124OK

Your code for show.html.erb at the bottom of the page doesn’t fix the DRY issue. I believe it should be:
<% if notice %>

<%= notice %>

<% end %>
<%= render @cart %>

2014-07-09The DRY issue is addressed in iteration F1
143ERROR

Adding this to application.js no longer works:
//= require jquery-ui

After about 15 minutes of fighting, I found this works:
1. gem install jquery-ui-rails
2. within Gemfile add this:
gem ‘jquery-ui-rails’
3. use this require in the example instead:
//= require jquery.ui.all

2014-07-09
108ERROR

The paragraph under current_card.rb states, that the code finally returns the new cart. As I see it, it doesn’t, but returns the cart’s id!

2014-07-09
200ERROR

The route mapping delete ‘logout’ => :destroy does not work.

42ERROR

“In effect, though, you can ignore that it’s a hash and pretend that Ruby has keyword arguments.”

It sounds like this should have been updated for Ruby 2.0

2014-07-08
47OK

The following sentence contains a query string within the URL, meaning a GET request is performed. However, the sentence indicates that a POST request is performed:

“The routing component receives the incoming request and immediately picks it apart. The request contains a path (​/line_items?product_id=2​) and a method (this button does a POST operation; other common methods are GET, PUT, PATCH, and DELETE).”

Thanks,

Matt

2014-07-08One can indeed POST to a URL containing a query string, and in fact, the Depot application does this.
156ERROR

assert_select ‘tr#current_item td’, /Programming Ruby 1.9/
The dot in the RegEx should be escaped.

2014-07-09
47ERROR

Mention of impossibility of instantiating modules. But subsequent statement says “module’s instance method”.

2014-07-08
140ERROR

(FYI the problems here could be due to changes in jQuery UI implementation)

The inclusion of:

form, div {
display: inline;
}

inside the scope of #side seems to be necessary since there is nothing to put side-by-side. Furthermore, this makes div#cart display: inline, which break the jquery-ui blind animation because div#cart has no natural height, which jQuery requires to complete the blind animation.

Removing this CSS rule fixes the animation. However, there is still a small issue where there is a hitch at the end of the animation due to two things:

1) CSS margin collapse of the h2 at the top of the cart causes jQuery to miscalculate the height of div#cart (very obvious in the web inspector)

2) jQuery determines the height of div#cart before the newly added line item is added to the table

These two elements cause jQuery to underestimate the height of div#cart, leading to a hitch at the end of the animation as the animation wrapper div is removed and div#cart jumps back to its natural height. 1) can be fixed by removing margin-top from the h2. 2) can be fixed by moving the show() call to after the cart HTML is replaced in create.js.erb.

169SUGGEST

Pg 169 includes the 2nd of two adjustments to orders_controller_test.rb in chapter (12 “Check Out”). However, the chapter has no steps for running “rake test”.

(Perhaps reader is expected to run “rake test” by habit by now. If so, this could usefully be noted at some point.)

Thanks!

2014-07-09
104ERROR

Book say to change this flag to true to enable caching:

config.action_controller.perform_caching = true

But it doesn’t work without this flag also being set to true:

config.cache_classes = true

91OK

To get the file products/index.html.erg to render properly in Firefox I had to add ‘class=“product”’ (no single quotes) to the opening table tag, and remove all the comments from the stylesheet file products.css.scss. I am developing on Windows 7.

2014-07-09class="products" should have been added to the body tag on page 75; I can't explain why comments in the css file wouldn't work (note: I develop using Firefox).
129OK

Between pages 129 and 130, essentially in the middle of a paragraph, while we are still talking about making a smarter cart, the sample codebase switches from being in depot_h, to being in depot_i. This is really confusing to someone who has screwed up their codebase and just wants to revert to some particular state that works.

It would be really helpful in general if the depot_#{letter} would line up with the chapter/section that is currently in progress. So, for example, section 10.3, also known as “E3” is called “Finishing the Cart”, but the associated codebases come from depot_h and depot_i. It would be much clearer if all of the codebase in “Finishing the cart” came from a directory called “depot_e3”

Thanks.

2014-07-09This is why the Playtime exercises encourage you to use git.
221TYPO

“Carrito bonita” -> “Carrito bonito”
because
carrito nombre masculino

153TYPO

$(document).on “ready page:change”, ->
\t$(‘.store .entry > img’).click ->
\t\t$(this).parent().find(‘:submit’).click()

produces that products will be added twice (Mac OS X 10.9 Safari 7.0.1/Chrome 31.0)

fix: $(document).on “ready, page:change”, ->

194SUGGEST

The changes made to the default ‘_form.html.erb’ file (to improve the appearance of the user creation/modification form) created by the Rails scaffolding have not been indicated with the small grey arrows on the left hand side of the code, as they are in other examples.

200TYPO

Should the route “delete ‘logout’ => :destroy” perhaps instead be “get ‘logout’ => :destroy” to permit logging out via a standard link in a browser?

120OK

Hello People,

Thanks for the fantastic reference. Maybe its just my lack of understanding here, but the following code (from the book) seems to work, but I don’t understand the magic.

  1. rails40/depot_g/app/models/cart.rb
    def add_product(product_id)
    current_item = line_items.find_by(product_id: product_id)
    if current_item
    current_item.quantity += 1
    else
    current_item = line_items.build(product_id: product_id)
    end
    current_item
    end

From playing with the code it isn’t obvious to me why I don’t need to write something more like:

current_item = line_items.find_by(product_id: product_id, cart_id: self.id)

current_item = line_items.build(product_id: product_id, cart_id: self.id)

I’m just wondering if there is some magic that helps a Cart get the LineItem that indeed corresponds to the particular Cart in question. If I don’t need to pass the cart id as I do in the two changed lines above, I think it might be good to explain why in this section.

Or is it maybe a bug?

Cheers :-)

2014-07-09Each cart has a collection of line_items that are specific to that cart. Therefore there is no need to specify the cart in a find operation over the list of line_items for that specific cart. If there is any magic involved here it is that the Cart.line_items.build method will automatically fill in the cart.
41SUGGEST

Where it says “Keys in a particular hash must be unique—you can’t have two entries for :drum.”, should say “Keys in a particular hash are unique—the last of multiple entries for :drum will cancel any preceding entries.”

Try the follwing in the console:
Product.create(name: ‘First name entry’, name: ‘Second name entry’)

2014-07-08
79OK

“Why test against 1 cent, rather than zero? Well, it’s possible to enter a number such as 0.001 into this field. Because the database stores just two digits after the decimal point…”
When we set the validation to greater_than: 0, values like 0.001 do get stored in the database, in spite of the schema explicitly saying “precision: 8, scale: 2”…
Not sure where the error is, but could it be in your explanation?

2014-07-09Sqlite3 doesn't directly support decimal data types; but database managers that are intended for use in production do. At this point in the book, we are just introducing concepts here, so I don't want to delve into more advanced topics like differences in databases.
127OK

Even after applying the changes, notably to the destroy method in the carts controller, I’m still capable of browsing to which ever cart I like, at carts/show/cart_id, click the empty button, and the cart is destroyed. So I’m able to delete someone else’s cart…

I’ve added to /test/controllers/carts_controllers_test.rb :

test “shold not destroy someone else’s cart” do
session[:cart_id] = nil
assert_difference(‘Cart.count’, 0) do
delete :destroy, id: @cart
end
end

And the result:

Failure:
CartsControllerTest#test_shold_not_destroy_someone_else’s_cart [/home/oz/rails/depot/test/controllers/carts_controller_test.rb:51]:
“Cart.count” didn’t change by 0.
Expected: 2
Actual: 1

2014-07-09This hole is closed in Iteration I3: Limiting Access
58OK

In introducing methods, you make use of a return statement that is in practice unwarranted since Ruby methods return their last-evaluated expression. To say the following would suffice to return the expected result:

`def say_goodnight(name)
result = ‘Good night, ’ + name
end`

2014-07-08The example shows how a return statement could be used; and the subsequent prose says that return is optional.
79OK

I think that, regarding the numerical validation of the price, it must be stressed that errors could also be produced by storing legal but unintended data as a result of type casting, conversions and maybe bugs performed before reaching the database.

If I use 0.0099999999999999999999 as price for the product, it passes validation, because somewhere between the interface and the database this number gets rounded to 0.01. I can’t think of a better example now, but I think you got the idea.

2014-07-09This is meant to be an introduction to validation at this point.
149ERROR

In the second paragraph, it says: “With that change in place, click any Add to Cart button, and you’ll see that the changed item in the cart glows a light green before fading back to merge with the background.”

The problem is that I don’t see any animation. I know the Jquery code is doing something, because running it from the Chrome console (first the css instruction, then the animate instruction) changes the background color to highlighted, and then back, but the change is immediate, not gradual. I tried the workarounds given by other users but I couldn’t make it work and I don’t want to pass a lot of time on it. I expect a comment from the authors, thanks.

149TYPO

In the cited code for the _cart partial, the line

Your Cart

should be

Your Cart

and that’s all!

2014-07-09
150ERROR

The code to put in create.js.erb seems wrong in two aspects: first, the line we add should be added between the two existing lines, otherwise it will make the test before changes are done to the DOM. Second, the test must be comparing to 2, not 1, since the least number of tr’s is 2 (we must count the total line).

Another comment: in JavaScript, equality comparison should be done with =. This is surely a typo due to the fact that Ruby uses .

150ERROR

The animation done with Jquery’s ‘show’ just doesn’t work. The cart is shown, but the changes are not animated. I also had the same problem with color highlighting in the previous iteration.

113OK

The correct way of accessing `product_id` from request’s params is: params[:line_item][:product_id], not params[:product_id]

2014-07-09I don't know how this reader came to that conclusion. Data from the log: \n \nStarted POST "/line_items?product_id=3" for 127.0.0.1 at 2014-07-08 23:04:47 -0400 \nProcessing by LineItemsController#create as */* \n Parameters: {"product_id"=>"3", "authenticity_token"=>"6eQBpEQn892GZL/TVaPtAXHe/TKl32Q8S3mKrF1jSf8="}
198ERROR

In the paragraph after the form code, there’s this phrase, which describes the parameters of the *_field_tag helpers: “The first is the name to give to the field, and the second is the value with which to populate the field.”

I think the phrase should be more precise in the sense that the second argument is also used to transport the value between controller and view. It is not just a value, but it’s more like a variable. I tried to write the precise phrase but I failed and I leave that to the authors.

72OK

Hyperlink for downloading index.html.erb points to incorrect content.

2014-07-09How is the content incorrect?
75TYPO

Seems there is a sentence or two missing from this content in the colored box: “A GET request is defined by HTTP to be used to retrieve
data; it isn’t supposed to have any side effects. Using this parameter in this way
indicates that an HTTP DELETE method should be used for this hyperlink.” The clue is “this parameter” has no clear referent.

2014-07-09The previous paragraph introduced the method parameter; I reworded these two sentences to make it clearer.
246TYPO

“Substitute your host’s name and your application’s directory path in the fol- lowing ServerName line”

should be

“Substitute your host’s name and your application’s directory path in the fol- lowing VirtualHost definition:”

86TYPO

Link on the top of the fixtures has changed in recent rails version (4.1.1) from Fixtures.html to FixtureSet.html

So:
api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

should be:

api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

2014-07-09
93TYPO

legend for Figure 16 Template not found

should not be that as the template index.html.erb, is created when using the rails scaffold controller generator with the index method: rails g controller Store index

2014-07-09
153TYPO

Iteration F5, rails40/depot_n/app/assets/javascripts/store.js.coffee
Rails 4.0.5, Turbolinks 2.2.2

The handler registered by $(document).on “ready page:change” fires twice when loading the site in the browser with a Refresh. This causes two click handlers to be registered for each “img” tag. In the end, this means that when an image is clicked, two copies of the same item are added to the cart.

289TYPO

Under the “Subsetting the Records Returned” heading, the text first alludes to the “all()” method but then refers to the “to_a()” method. I am unsure if this is a typo or I am just misreading the text. If the case of the latter, I’m sure there can be some added clarity. Thank you.

164ERROR

in the scaffold code generated by rails (4.1) the following:

<% @order.errors.full_messages.each do |msg| %>

  • <$= msg %>

  • <% end %>

    should be:

    <% @order.errors.full_messages.each do |message| %>

  • <%= message %>

  • <% end %>

    2014-07-09
    187SUGGEST

    Should the line:

    order = orders[0]

    be better placed in the following section of code since it is logically related to the following assertions?

    ie.

    order = orders[0]
    assert_equal “Dave Thomas”, order name

    2014-07-09
    196SUGGEST

    Wouldn’t it be better if there is a note that emphasises that in testing the create method in the user controller the user name (ie ‘sam’) should be different from what we have in the fixtures.yml :one record (ie ‘dave’)

    108OK

    Not to sure what to do with the code on the top of the page, not clear instructions.

    2014-07-09I can't track down what code is being referenced based on this description.
    81OK

    $ rails g migration add_image_to_pins image:string

    Do you mean?

    $ rails g migration add_image_to_pins image_cache:string

    2014-07-09I don't see anything remotely like this text in this book.
    81OK

    4 These uploadersare reusable and the same one can be mounted on multiple models
    in our pinmodel:
    app/uploaders/image_uploader.rb (WRONG, THIS IS NOT A MODEL)

    do you mean?

    2014-07-09I don't see anything remotely like this text in this book.
    104ERROR

    config/environments/development.rb
    only after setting both of the following to true did caching work properly
    config.cache_classes = true
    config.action_controller.perform_caching = true

    147TYPO

    In Iteration F3:Highlighting Changes the jQuery-UI library has been updated and the syntax for the entry in application.js to include the Blind Effect is now:
    //= require jquery-ui/effect-blind
    Instead of:
    //= require jquery.ui.effect-blind

    Source is; rubydoc.info/gems/jquery-ui-rails/frames

    159147ERROR

    depot code jquery-ui effect blind import:

    in depot code the
    app/assets/javascripts/application.js
    lists the import:
    " //= require jquery.ui.effect-blind" at line 24

    at github.com slash joliss slash jquery-ui-rails you’ll find the correct import:

    //= require jquery-ui/effect-blind

    148TYPO

    The color does not fade back. It is a book typo and a file typo.
    File with typo is rails40/depot_m/app/views/line_items/create.js.erb
    There is a space at the beginning of line
    animate({’background-color’:‘#114411’}, 1000);
    Remove the space and color fades as expected.

    417TYPO

    Text:
    “…we modify our controller to call paginate()…”

    Code extract:
    @orders = Order.order(‘created_at desc’).page(params[:page])

    Text states “paginate()” but code extract uses “page()”.

    155ERROR

    The code within app/views/layouts/application.html.erb fails to display a cart when the cart is initially empty and the first product is added to it.

    322TYPO

    The page number might not be correct - I’m using iBooks, and the page no. depends on the window size.

    The error is in the code for:
    “rails40/depot_m/app/assets/javascripts/application.js”:

    Is: “*​//= require jquery.ui.effect-blind”
    Should be: “*​//= require jquery-ui/effect-blind”

    109SUGGEST

    Book text:

    class Cart < ActiveRecord::Base
    ➤ has_many :line_items, dependent: :destroy
    end

    But if LineItem is a Model, shouldn’t “has_many” be:

    ➤ has_many :line_item, dependent: :destroy

    using the (singular) model name?

    I found the answer relating specifically to “has_many” here:

    “guides.rubyonrails.org/association_basics.html#the-has-many-association”

    Note the highlight there: “The name of the other model is pluralized when declaring a has_many association.”

    Suggest a note on this maverick association in your book as it differs from “belongs_to”, “has_one” and is confusing.

    Thank you.

    108ERROR

    Page 107: after running the scaffold to create the Cart, and migrating it…
    the code on page 108 for “/app/controllers/concerns/current_cart.rb” does NOT get created automatically. Are we supposed to create a file in this path? If so, why? Or should the code listed on page 108 supposed to be the contents of “/app/controllers/carts_controller.rb”?

    396TYPO

    Two descriptions of raw() method are given which contradict each other.

    33TYPO

    Top of the page : the end sentence dot shouls not be on th ebeginning of the second line… probably due to trhe change of font.

    156TYPO

    store_controller_test.erb section has a typo in this line:

    assert_select ‘.store .entry > img’, 3

    it doesn’t work unless you remove the “>” - maybe this was an unintentional carryover from the js/coffeescript? It should be (at least what works for me)

    assert_select ‘.store .entry img’, 3

    xvERROR

    The link on pragprog.com for note #2 takes you to tarballs, but the .tgz tarball is actually rails30. The zip file is correct.

    39TYPO

    Not a huge problem, but some code specifies a space in ‘Good night, ’ but the output is shown as ‘Goodnight…’. Unless there’s something I don’t get about some automatic concatenation, something went wrong here. Text copied below.

    def say_goodnight(name)
    result = ‘Good night, ’ + name return result
    end

    1. Time for bed…
      puts say_goodnight(‘Mary-Ellen’) # => ‘Goodnight, Mary-Ellen’ puts say_goodnight(‘John-Boy’) # => ‘Goodnight, John-Boy’
    147TYPO

    It seems the notation for jquery-ui changed from:
    //= require jquery.ui.effect-blind

    to

    //= require jquery-ui/effect-blind

    The older version doesn’t work with the new library (at least in my configuration).

    Thanks,

    Ronaldo

    100ERROR

    This error has been reported before - just note that if you use the old syntax, the animation may fail with no error indicated. The line item stays bright green. (page number is bogus - epub does not have any)
    In Iteration F3:Highlighting Changes the jQuery-UI library has been updated and the syntax for the entry in application.js to include the Blind Effect is now:
    //= require jquery-ui/effect-blind
    Instead of:
    //= require jquery.ui.effect-blind

    1ERROR

    In downloadable example code, in code/rails40/depot_n though depot_v contains an incorrect comment syntax that raises a runtime error in /assets/javascript/store.js.coffee:

    ExecJS::RuntimeError in Store#index
    Showing <…>/code/rails40/depot_o/app/views/layouts/application.html.erb where line #8 raised:

    SyntaxError: [stdin]:5:1: unexpected //

    The code in question is as follows:
    # Place all the behaviors and hooks related to the matching controller here.
    # All this logic will automatically be available in application.js.
    # You can use CoffeeScript in this file: …/coffeescript.org/

    //#START_HIGHLIGHT
    $(document).on “ready page:change”, ->
    $(‘.store .entry > img’).click ->
    $(this).parent().find(‘:submit’).click()
    //#END_HIGHLIGHT

    Removing the “//” before “START_HIGHLIGHT” and “END_HIGHLIGHT” resolves the error.

    196ERROR

    In Iteration F3 we add “gem ‘jquery-ui-rails’” and then add it to application.js with:

    //= require jquery.ui.effect-blind

    but that throws this error:

    couldn’t find file ‘jquery.ui.effect-blind’

    according to the Github page:
    joliss/jquery-ui-rails

    it should be added like this:

    //= require jquery-ui/effect-blind

    147ERROR

    The changed line should be
    require jquery-ui/effect-blind
    instead of
    require jquery.ui.effect-blind

    Refer - stackoverflow.com/questions/24819381/application-js-cant-find-jquery-ui-effect-blind

    237SUGGEST

    Apache 2.4 has changed the access configuration:

    Remove `Order allow, deny` and `Allow from all` and add `Require all granted`

    <VirtualHost *:80>
    ServerName depot.yourhost.com
    DocumentRoot /home/rubys/deploy/depot/public/

    AllowOverride all
    Options -MultiViews

    1. Order allow,deny
    2. Allow from all
      Require all granted

    238TYPO

    Apache 2.4 has changed some of the naming conventions:

    The virtual hosts file needs now the .conf extension. Which means instead of depot it is depot.conf

    sudo a2ensite depot.conf

    237SUGGEST

    Apache 2.4 has change security settings.

    If the web application is outside /var/www/, e.g. in the /home directory it is necessary to add the directory to the apache2.conf otherwise you get an authz_core: error "client denied by server configuration: /home/rubys/deploy/depot/public/.

    To fix this add to apache2.conf (Ubuntu)


    Require all granted

    147TYPO

    ‘//= require jquery.ui.effect-blind’ doesn’t work. Try ‘//= require jquery-ui/effect-blind’ instead.

    See stackoverlow - /questions/24819381/application-js-cant-find-jquery-ui-effect-blind

    147ERROR

    ‘//= require jquery.ui.effect-blind’ doesn’t work. Try ‘//= require jquery-ui/effect-blind’ instead.

    See stackoverlow - /questions/24819381/application-js-cant-find-jquery-ui-effect-blind

    218ERROR

    When I toggle between the English and Spanish versions of the store, the “Add to Cart” button text does not change—it always retains its initial value. I’m assuming this is because the buttons are created inside a cache block?

    147ERROR

    The effect-blind jQuery UI module should be included as follows: `//= require jquery-ui/effect-blind` instead of `//= require jquery.ui.effect-blind`. More information can be found at github: joliss/jquery-ui-rails

    153ERROR

    After I add the Ajax to make the images clickable, when I click on the image it adds two of the item to my cart.

    147ERROR

    Dear brilliant writers of this book,

    It’s a very minor issue, but I wanted to do something back At Chapter 11. Task F: Add a Dash of Ajax, when implementing the Yellow Fade Technique, you’re asking us to require jquery.ui.effect-blind. For me that didn’t work (resulted in a not-found error). I had to change it to: jquery-ui/effect-blind.
    As I said, very minor but maybe still handy for future readers :)

    Cheers,

    Abel

    153SUGGEST

    Footer link 3 to Coffee Script is no longer valid, leads to 404 error page. Suggest updating to coffeescript.org.

    147ERROR

    In the code change for Download rails40/depot_m/app/assets/javascripts/application.js, the changed line:

    //= require jquery.ui.effect-blind

    is no longer valid. The line must be changed to:

    //= require jquery-ui/effect-blind

    due to changes in the library. See stackoverflow.com/questions/24819381/application-js-cant-find-jquery-ui-effect-blind

    189SUGGEST

    Chapter 13 Task H: Sending Mail ends on an unstable note. The reader is not guided to run their tests, and is not guided on how to handle any errors that may crop up in the process.

    181ERROR

    The file rails40/depot_r/app/controllers/orders_controller.rb directs the user to add the line “OrderNotifier.received(@order).deliver”.

    However, with the most recent version of Rails (>4.2), this crops up a warning stating:

    “DEPRECATION WARNING: `#deliver` is deprecated and will be removed in Rails 5. Use `#deliver_now` to deliver immediately or `#deliver_later` to deliver through Active Job. (called from block in create at /vagrant/work/depot/app/controllers/orders_controller.rb:43)”

    This can by fixed by changing the inserted line to:

    “OrderNotifier.received(@order).deliver_now”.

    193ERROR

    The section that states “the index view doesn’t display notice information” is no longer valid. By default, `rails generate` now adds the following to the top of each show or index view file:

    <%= notice %>

    It is still nice to add the check that is in the text to not display the notice markup unless there is one.

    194SUGGEST

    The suggested changes to _form.html.erb on page 194 of the PDF are missing the arrowsemarking where changes are being added to the existing file.

    195SUGGEST

    The user is never directed to add any input to the fields before being directed to click “Create User”. This is confusing, as it jumps directly to “After clicking Create User”, which implies that there’s a missing step that’s been omitted.

    197ERROR

    The layout for /app/views/sessions/new.html.erb file is missing the “field” classes from the two divs for the login form on the page. This causes the form to render incorrectly.

    94ERROR

    The line for the store’s index page: <%= sanitize(product.description) %> should be wrapped in a p tag to match the CSS. Using the provided markup makes the description appear under the image.

    165ERROR

    When image is clicked, items are added to cart twice. Adding `.not(“.clickable”).addClass(“clickable”)` fixed it:

    $(document).on “ready page:change”, ->
    \tconsole.log(‘ready or page change’)
    \t$(“.store .entry > img”).not(“.clickable”).addClass(“clickable”).click ->
    \t\tconsole.log(‘image clicked’)
    \t\t$(this).parent().find(‘:submit’).click()

    168ERROR

    The AJAX unit test (test_should_create_line_item_via_ajax) failed with this error:

    No JQuery call matches [:html, “#cart”]

    To fix, I put the call to assert_select_jquery in a do block attached to assert_response :success

    147TYPO

    There is a sentence that reads “Now that we have the jQuery-UIjQuery-UI library available”. There are two ‘jQuery-UI’

    83ERROR

    Working on section 6.2 Iteration A2: Making Prettier Listings…NEED HELP PLEASE!

    media.pragprog.com/titles/rails4/code/rails40/depot_a/app/assets/images/

    am being denied access to this server. getting error. Forbidden

    You don’t have permission to access /titles/rails4/code/rails40/depot_a/app/assets/images/ on this server.

    Apache/2.4.7 (Ubuntu) Server at media-origin.pragprog.com Port 80

    I would need access to populate the DB with images.

    Please advise.

    Thank you,
    Chris Arzoomanian

    100ERROR

    When I look at the application in the browser (Chrome) there is no header or sidebar formatting. To be sure I did not make an error, I loaded depot_e, and had the same problem. The menus, the logo, etc is all there, but no header or side bar.

    132ERROR

    At the top of PDF page 132, we see a line from rails40/depot_i/app/assets/stylesheets/carts.css.scss:

    .total_line .total_cell {

    There should be a comma after the first class attribute value, ``.total_line’’, making
    this really a technical typo, I suppose.

    95ERROR

    The code block in products_controller.rb is curently:

    @update = {
    title: ‘Foo Bar’,
    description: ‘Foos and bars, bars and foos.’,
    image_url: ‘foo.jpg’,
    price: ‘19.99’
    }

    This triggers an exception when running the tests because the test expects an ActiveRecord object. The @update instance var ought to be:

    @update = Product.new(
    title: ‘Foo Bar’,
    description: ‘Foos and bars, bars and foos.’,
    image_url: ‘foo.jpg’,
    price: ‘19.99’
    )

    Alternatively, it may be better to just have the reader update the products.yml fixture. This would be a slight digression, but would help explain the @product = products(:one) line of code in the controller.

    Let me know what you all think. I’ve been a software engineer using Ruby for a few years and am diving deeper into Rails and wanted a refresher, and I’m enjoying going through this book so far!

    229ERROR

    The locale switcher snippet creates a form without a method which defaults to POST and thus ends up trying to access an unavailable route. The snippet should be:

    <%= form_tag store_path, method: :get, class: ‘locale’ do %>
    <%= select_tag ‘set_locale’,
    options_for_select(LANGUAGES, I18n.locale.to_s),
    onchange: ‘this.form.submit()’ %>
    <%= submit_tag ‘submit’ %>
    <%= javascript_tag “$(‘.locale input’).hide()” %>
    <% end %>

    228ERROR

    In the OrdersController snippet we localize the thanks message with I18n.t(‘.thanks’) but the following lines suggest you can add the locale message as:

    en:
    thanks: “Thank you for your order”

    The localization will not be found because it expects to find it based on controller name and action i.e.

    en:
    orders:
    create:
    thanks: “Thank you for your order”

    149137ERROR

    After rails40/depot_j/app/views/carts/show.html.erb, this sentence appears: “The partial template itself is simply another template file (by default in the same directory as the object being rendered and with the name of the table as the name.” That sentence has a couple of problems. First, to what does “the name of the table” refer? I don’t see any table name. Second, “in the same directory as the object being rendered” doesn’t really make sense. The object being rendered lives in memory (RAM) and is not in a directory on disk. (I’m guessing the intent was to avoid a wordier construct such as “in the same directory as the view templates for the object being rendered”.)

    151139ERROR

    The line <%= render cart %> breaks the controller unit tests badly. The problem is that cart may be nil (for instance, if the URI path is “/carts” (invoking carts#index). The fix is to use this instead:
    <% if cart %> <%= render cart %>
    <% end %>

    Moral of the story: Run unit tests after every change, no matter how trivial. :-)

    163151ERROR

    The <%= hidden_div_if(cart.line_items.empty?, id: 'cart') do %> line also breaks controller unit tests. Again, it is not safe to assume cart is not nil.

    Fix: <%= hidden_div_if((cart.nil? or cart.line_items.empty?), id: ‘cart’) do %>

    Categories: