By Developers, For Developers

Historical errata for Crafting Rails 4 Applications

PDF PgPaper PgTypeDescriptionFixed onComments
7TYPO

The code for pdf_renderer/1_prawn/test/dummy/app/views/home/index.pdf.erb reads as follows:

“This is was generated by Prawn.”

which I assume is a typo.

2013-06-12
15TYPO

The occurrence of “pass” should probably be “passes” in the following text:

At the end, render_to_string({}) simply pass template: “#{controller_name}/#{action_name}” to the view renderer object.

2013-06-12
348TYPO

In the Playing with Prawn section in Creating Our Own Renderer there is a typo in the code. It says “bundler install” should be “bundle install”.

2013-06-12
135ERROR

The assert in navigation_test.rb should be assert_equal

36TYPO

Acitve Model , should be Active Model

23TYPO

at the bottom of the page (23 printed on pdf or 34 in Preview):
“should return The code tag should not be here.. This is exactly”

I think it should be:
“should return. The code tag should not be here. This is exactly”

29TYPO

“Is the request send to the proper URL?”

use sent :

Is the request sent to the proper URL?

5242TYPO

… which we will consider to be The code tag should not be here. for now, and the locals variable …

32SUGGEST

The code:

def initialize(attributes = {})
attributes.each do |attr, value|
self.public_send(“#{attr}=”, value)
end if attributes
end

Seems like a bad idea. Most probably opens a pretty large hole in the applications, since anyone can now craft requests with params that will result in methods being called.

For example posting `_validate_callbacks=foo` will set callbacks to be ran on save. I assume this could be used to run arbitrary code, even.

I think it should whitelist against the possible attributes, something like this:

def initialize(attributes = {})
attribute_names.each do |name|
self.public_send(“#{name}=”, attributes[name]) if attribute.has_key? name
end if attributes
end

36SUGGEST

module MailForm
class Base
include ActiveModel::Conversion
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations

Perhaps we should use “include ActiveModel::Model” instead, since it is Rails 4.

182TYPO

In the second full paragraph of the page where it says I18n.t(“foo.bar”) #=> “bar” it must say I18n.t(“foo.bar”) #=> “baz”

163TYPO

conf*s*ig.secret_key_base

3030ERROR

555-555-0199@example.com

69ERROR

After typing code in templater/2_improving/test/integration/cms_test.rb file,
running rake test, I get an error not finding ActiveSupport::IntegrationCase.
Replacing this with ActionDispatch::IntegrationTest works.

69SUGGEST

Sorry for previous error reporting (#53120), it wasn’t an error.

Anyway, while reading the book and typing examples, it could be interesting to add line_numbers to examples ; it would help to figure out where we should write code in the file if not used to.

77TYPO

$ rails plug-in new handlers
should be
$ rails plugin new handlers
(without dash)

86SUGGEST

$ rails g mailer —help
Seems to be broken in Rails 4.0.1 (works in Rails 3.2.12)

86SUGGEST

Sorry again : it works (I was not in the folder of my rails application). You wrote it (but maybe add “change to your dummy app folder”, to avoid other reader fall in the same error I did.

33SUGGEST

In the Validators section of Taking it to the Next Level, the reader is guided in creating a supposedly missing AbsenceValidator. This validator was added in Rails 4. The example should probably be updated to a non-existing validator or name.

64TYPO

rails plug-in new handlers

s/plug-in/plugin/

93ERROR

The current version of the Listen gem (2.x) must have start explicitly called on the value returned from Listen.to in order to start the listener. Either add this to the example code or specifically require a pre-2.0 version of the gem.

def self.start_listener(event, directories)
Thread.new do
Listen.to(*directories, latency: 0.5) do |_modified, _added, _removed|
subscribers.each { |s| s << event }
end.start
end
end

77ERROR

It says to override format and return nil, however, it looks like you need to override formats and return an array with nil.

159TYPO

it says confsig.secret_key_base instead of config.secret_key_base on the third paragraph

162ERROR

When I ran the integration test for the translator app, I kept getting the error “:pl is not a valid locale”.

Per the discussion at github.com/rails/rails/issues/13164, I added the line
config.i18n.enforce_available_locales = false
to the config/application.rb file and the error went away.

22SUGGEST

The current image made me think they were just called for side-effects, but the code shows something else.
Instead it could show flow of data through the methods, i.e. _normalize_render pipes into render_to_body

Categories: