Errata

RESTful Rails Development

Errata for RESTful Rails Development

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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

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

Version Location Description Submitted by Date submitted
PDF, ePub Page xvii
in paragraph below Chapter 15 heading

End of paragraph reads: "... scalability in Rails is a big issues."

It should be: "... scalability in Rails is a big issue."

Andreas Wachowski  Sep 23, 2015 
ePub Page ch. 4
"HTTP Semantics" Section

in chapter four under the HTTP Semantics section the word The is repeated:

"The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The The URI in a POST request identifies the resource that will handle the enclosed entity. "

Anonymous  Mar 15, 2021 
PDF Page 44
Last paragraph before "Scaffolding the Models" section

Users following along with the book who did not previously have MySQL installed will encounter a "Can't connect to local MySQL server" error upon executing the rake 'db:create' command if they don't first issue the 'mysql.server start' command. This missing step should therefore probably be mentioned.

Russ Martin  Dec 07, 2015 
PDF, ePub Page 45
third para

on 45 last para:

class CreateCategories > ActiveRecord::Migration

should be

class CreateCategories < ActiveRecord::Migration

on 46, Sample code for migration reads:

class CreateCategories > ActiveRecord::Migration def change
create_table :categories, {:id =&gt; false} do |t|

it should be

class CreateCategories < ActiveRecord::Migration def change
create_table :categories, {:id => false} do |t|


similarly on 48 the text in two places:

class CreateLinks > ActiveRecord::Migration

should be

class CreateLinks < ActiveRecord::Migration

Vincent Trivett  Jan 11, 2016 
PDF Page 46
1st full code snippet

You do not need the following columns in addition to t.timestamps:

t.date :created_at
t.date :updated_at

Timestamps, by definition, creates those two columns, in datetime format. In this case, due to the duplication, t.timestamps actually overwrites the two manually-created columns. The same error can be found on page 48 in the second full code snippet.

Maggie Baker  Jun 15, 2016 
PDF Page 50
Top of page: Gemfile sample

The Gemfile shown will not work as expected because, as mentioned by others, the class-level respond_to has been moved into the responders gem. However, there also seems to be problems with active model serializers and using the root key option. Specifically, active model serializers version 0.10.0.rc2 or even 0.10.0.rc3 seems to ignore the root option, causing JSON responses to not include the root key.

I have found the following gemfile to work as the tutorial expects, including root keys:

source 'https://rubygems.org'
ruby '2.2.0'
gem 'rails', '4.2.5'
gem 'rails-api'
gem 'mysql2'
gem 'responders', '~> 2.0'
gem 'active_model_serializers', '~> 0.8.0'

Russ Martin  Dec 08, 2015 
Printed Page 51
Bottom

When I curl the category/show endpoint I get the following error:
NoMethodError (undefined method `title' for #<Category:0x007fb3850b9808>):
app/controllers/api/v1/category_controller.rb:6:in `show'

This is after using the responders gem, and instead of inheriting from ActionController::API, I have to inherit from ActionController::Base. It seems this changed with rails 4.2 and some people are having trouble with rails-api..

Next, I was able to fix the 500 error for title above with changing the serializer implementation on page 50:

class CategorySerializer < ActiveModel::Serializer
attributes :cat_title, :cat_subcats
end

This fixed the curl response for me, and now receive: {"category":"Science","cat_subcats":34}

Dave Marr  Nov 09, 2015 
PDF Page 52
In the code for the Graphs controller

In the graphs controller, the variable name is wrong:

cat = params[:category] || 'sports'
@category = Category.where(:cat_title => cat.capitalize).first

It should be this:

category = params[:category] || 'sports'
@category = Category.where(:cat_title => cat.capitalize).first

Again, see your repo where it is defined correctly:
https://github.com/hiromipaw/wikicat/blob/master/app/controllers/api/v1/graphs_controller.rb

P.S. (I made an earlier errata note on the rails generate for this controller and incorrectly said it was on page 53 when it should have been page 52. Sorry for the errata errata :) )

Ryan Benedetti  Nov 29, 2015 
PDF Page 53
Rails generate code near middle of page

We are going to create a controller that will use the link serializer and build the category graph:

$ rails generate controller api/v1/graph show

The controller is singular but it should read as follows:

$ rails generate controller api/v1/graphs show

The controller is "graphs_controller" in your Github repo:
https://github.com/hiromipaw/wikicat/blob/master/app/controllers/api/v1/graphs_controller.rb

Ryan Benedetti  Nov 29, 2015 
PDF Page 53
Top of page

The curl step will not work unless a line is first added to routes.rb:

get '/graph/:category', to: 'graph#show'

Russ Martin  Dec 08, 2015 
PDF Page 57
first paragraph

missing letter
epresentation -> representation

Anonymous  Oct 12, 2015 
Printed Page 74
4th paragraph

Items left out to get the Main_topic_classifications listing to work are:

in graph_controller#index

def index
@links = Link.where(:cl_to => "Main_topic_classifications", :cl_type => "subcat")
render :json => @links, each_serializer: LinkSerializer, root: "main_topic_classifications"
end

in routes.db

get 'graph/', :to => 'graph#index'

and finally a command to curl

curl http://localhost:3000/api/v1/graph/

Dave Marr  Nov 09, 2015 
PDF Page 75/304
First code paragraph

the code should be
:cat_title =>
instead of
:cat_title =&gt;

and 2 lines later
render :json => @category,
instead of
render :json =&gt; @category,

Anonymous  Oct 12, 2015 
PDF Page 82
Netherlands

create_table :categories, {:id =&gt; false} do |t|

should be:

create_table :categories, {:id => false} do |t|

Kiffin Gish  Jun 20, 2015 
PDF Page 84
Netherlands

The name of the gem is not mentioned and it is not readily evident that the following line has been added to the Gemfile:

gem 'active_model_serializers'

Kiffin Gish  Jun 21, 2015 
PDF Page 85
gemfile

FYI - respond_to has be deprecated in Rails 4.2.2 and moved into the responders gem and AMS needs the version in the gemfile or the serializer won't fire.

To make the existing code & serializers work in 4.2.2, add:

gem 'responders', '~> 2.0'

and add version to the AMS line:

gem 'active_model_serializers', '~> 0.10.0.rc2'


Anonymous  Jul 17, 2015 
PDF Page 86
Netherlands

Everywhere in the code samples:

* replace '=&gt; ' with '=>'
* first line gives file name but looks like part of the code
* indicate changed and/or new lines with a symbol

Kiffin Gish  Jun 21, 2015 
PDF Page 88
generating graph controller

The PDF says to run 'rails generate controller api/v1/graph show' (singular graph) but the source code expects that to be graphs (plural). (Unless that changes later in the book).

You also forgot to mention that you need to edit the route to add the category parameter and map to the show action.

Anonymous  Jul 17, 2015 
PDF Page 88
setting category from params

You can replace the ternary operator in both the category and graphs controllers with a simple "||" as follows:

cat = params[:category] || 'sports'

Less typing and reads a little cleaner (more railsy)

Anonymous  Jul 17, 2015 
Printed Page 112
First full paragraph

A heads up about the CSV data being imported. There are trailing commas on each line that cause Postgres to reject the file. A quick fix is to use sed (mac/Linux) to iterate through each file and remove the trailing comma on each line. Example:
`$ sed 's/,$//' wikipedia_articles_201107.csv > wiki_no_commas.csv`

Repeat for city blocks and locations files and make sure to point the SQL code in the book at the new output files.

Gary Grumbley  Jan 05, 2016 
ePub Page 180
CategoryController code

In Rails 4.2.x, respond_with and the corresponding class-level respond_to have been moved to the responders gem. The respond_to :json will not work unless the steps below are taken:

Add to Gemfile:
gem 'responders'

Console command:
bundle install

Jeff Costa  Nov 03, 2015