The 1st edition for Rails 3 in Action contained some errata. Listed below is the known errata for this edition and the fixes for them. If you do discover any more, please do not hesitate to let us know on the Rails 3 in Action Forum.
It is our priority to fix these up and deliver you the best book possible.
Ruby on Rails 3.1 requires a JavaScript runtime for default gems used such as uglifier. If you do not have one installed, you will see this error:
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
Please consult the README for execjs, which mentions possible runtimes. We would recommend the Node.js, as it provides the V8 JavaScript engine and is most likely installable using the package manager for your system if you're on a Linux-based system.
The mgiration inside this listing still uses the old Rails 3 syntax and may confuse readers who are unfamiliar with it. The migration command will actually output a migration that looks like this:
class CreatePurchases < ActiveRecord::Migration
def change
create_table :purchases do |t|
t.string :name
t.float :cost
t.timestamps
end
end
end
The self.up and self.down methods can still be used, but are now primarily used when it's not clear to Rails how to run the migration both forwards and backwards. In this migration's case, it is obvious to it (running it forward creates the table, running it backwards drops the table) and so we can use the change syntax.
The following sentence is in error:
By using <%=, the Ruby code is evaluated but not output.
It should read like this:
By using <%=, the Ruby code is evaluated and the result is output.
cucumber-rails version should be specified.(PT: 21821827)The latest version of Cucumber does not contain the web_steps.rb file. The book was written for cucumber-rails 1.0.6 and this change came shortly after the book was published.
To fix this, specify a version for the gem in the Gemfile:
gem 'cucumber-rails', '1.0.6'
dynamic_form gem location is incorrect (PT: 18476389)
It is suggested to put the dynamic_form gem underneath the coffee-rails gem inside the Gemfile. This is in error, as this would place it inside the :assets group meaning that it would not be loaded in the development environment.
Rather than placing this gem inside the assets group, this gem should be placed immediately after it to ensure it is always loaded in all environments.
rake assets:precompile should be run before launching the production environment (PT: 18476389)
Due to asset serving having been turned off automatically in the production environment, assets will need to be precompiled by running rake assets:precompile before launching the server in production. If this is not run, the styles for the application will be missing.
After this example we should use rake assets:clean to clean the assets out of the public/assets directory, otherwise they would be cached and any modifications we made to assets inside app/assets would not come into play.
The links for "Edit" and "Delete" inside Listings 8.12 and 8.13 should instead be for "Edit Ticket" and "Delete Ticket" respectively.
class is missing for permissions table (PT: 19679359)
The table element in Listing 8.16 requires a class attribute to be styled correctly.
This beginning of this element should be defined like this:
<table class='permissions'>
assets_controller_spec.rb -> files_controller_spec.rb (PT: 19679847)
The references to spec/controllers/assets_controller_spec.rb on these two pages should actually be referring to spec/controllers/files_controller_spec.rb instead.
new action in the FilesController is overdone (PT: 19758699)The code in this action is excessive and results in this:
def new
@ticket = Ticket.new
asset = @ticket.assets.build
render :partial => "files/form",
:locals => { :asset => asset }
end
This could be simplified into just this:
def new
@ticket = Ticket.new
@ticket.assets.build
render "files/form", :asset => asset
end
The code inside this listing that reads as this:
"→" + render(comment.state)
Should instead read like this:
render(comment.state)
li element regression (PT: 20037269)
On page 274, the li element for a state looks like this:
<li id='state_>%= state.id %>'>
<%= state.name %>
<% if state.default? %>
(Default)
<% else %>
<%= link_to "Make Default", make_default_admin_state_path(state) %>
<% end %>
</li>
Later on, on page 275, it is recommended to change this element to this:
<li id='state_>%= state.id %>'> <%= state.name %> <%= link_to "Make default", make_default_admin_state_path(state) %>
This is in error. This element on page 274 should just update the li's element to have an id attribute, like this:
<li id='state_<%= state.id %>'>
While the element on page 275 should be the one to add the link:
<li id='state_>%= state.id %>'>
<%= state.name %>
<% if state.default? %>
(Default)
<% else %>
<%= link_to "Make Default", make_default_admin_state_path(state) %>
<% end %>
</li>
The first code example on this page suggests using the Factory method within the console to generate a new object:
user = Factory(:user)
user.confirm!
user.permissions.create(:object => Project.first,
:action => "view")
This won't work in the development environment as it has not loaded the factory definitions. To fix this, FactoryGirl.find_definitions must be called before referencing the factory:
FactoryGirl.find_definitions
user = Factory(:user)
user.confirm!
user.permissions.create(:object => Project.first,
:action => "view")
The Scenario in Listing 11.2 is missing a step for giving the user permission to change the state. The first line of this Scenario should be this:
Given "user@ticketee.com" can change states on the "Ticketee" project
Without this line, the user does not have permission to change the states and so they are unable to do so.
The content type checking in the untitled listing here is too strict. It performs this:
p.content_type == content_type
Where instead it would be better to check for inclusivity:
p.content_type.include?(content_type)
include_root_in_json (PT: 19208829)The objects returned from the API in this chapter may not contain the element's type as the root node due to a last-minute change in Rails 3.1. This issue is adequately shown in this Stack Overflow post.
If you are encountering this issue, it is recommended that you create a new file called config/initializers/wrap_parameters.rb and define this content in it:
ActiveRecord::Base.include_root_in_json = true
The directory "spec/v1/api" is incorrectly, and should instead be "spec/apis/v1". This is used to reference the projects_spec.rb file in the second paragraph on this page.
This Listing contains two if statements checking for @current_user.admin?. There should only be one.
The description leading into Listing 13.13 says that we use a context block, but we actually don't.
This Listing incorrectly references the method to get the status code for the response as code in this line:
last_response.code.should eql(401)
This line should actually read like this:
last_response.status.should eql(401)
This page mentions that we need to create 20 tickets, but the example creates 5:
With this setup, you can begin the context for your index action and then in a before block, create 20 tickets for the project by using these lines after the let(:project) line:
This text should read "create 5 tickets", not 20.
The reference to the @@user_class variable on this page is incorrect. A variable with the double-@ prefix (@@) is a class variable, where in this case we should be referencing an instance variable for the class.
The config/initializers/forem.rb initializer pre-initializes the user_class variable and so the test in Listing 17.12 will always break. This variable must be reset to nil before this test and reset after it, by putting this code at the beginning of it:
before do
Forem.user_class = nil
end
after do
Forem.user_class = User
end
This method incorrectly references the @user_class variable as just @user and the ConfigurationNotSet exception as ConfigurationNotFound. It should be written like this:
def self.user_class
error = "Please define Forem::Engine.user_class" +
" in config/initializers/forem.rb"
@user || raise(ConfigurationNotFound, error)
end
Forem::UserExtension (PT: 18611295)
In the summary of Chapter 17, there is mention of a Forem::UserExtension module. This existed in draft versions of the chapter but does not exist in this first version. It is mentioned in error.
On the Back Cover, in Ryan Bigg's bio, the word "Sydney" is mispelled as "Syndey".