Errata

Ajax on Rails

Errata for Ajax on Rails

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
Printed Page 45
Custom Helpers

as of Rails 2.3.5, button_to_remote has been defined as part of ActionView::Helpers::PrototypeHelper
Creating a new button_to_remote causes a wrong number of arguments (3 for 2) in all submit_to_remote calls

TW Scannell  Feb 03, 2010 
Printed Page 39
First code block

The link_to_remote in the first code block returns the most of the html page of /chapter3/reverse.html.erb rather than the reverse of what is entered in the input.

I am doing the examples with Rails.2.3.5 which generated a small page in /chapter3/reverse.html.erb, that says:

<h1>Chapter3#reverse</h1>
<p>Find me in app/views/chapter3/reverse.html.erb</p>

If you look at page 34 and in your chapter3_controller, you will see that the action for reverse is
@reverse_text = params[:text_to_revers].reverse

@reverse_text is available to the template at /chapter3/reverse.html.erb, but not used. all you get back is the html contents of that template (plus the layout)

Change chapter3_controller#reverse to read:

def reverse
render :text => params[:text_to_reverse].reverse
end

and now the example works as the template is ignored.

This, of course may muck something else up later. I haven't read ahead..

Good luck.

TW Scannell  Jan 31, 2010 
Printed Page 55
Example at top of page

"chapter3" is the wrong controller (the action has just been added to "chapter4_controller"). Infact, the controller does not need to be explicitly referenced in this case.

Paul Krause  Dec 03, 2009 
Printed Page 40, 41
Forms section (p.40) and index.rhtml (p.41)

I am not sure if this is a change in Rails 2.0, but this usage of form_tag will not work.
Firstly, the form needs to terminate with <% end %>.
Secondly, a "do" is needed to handle the block in the form:

<% form_tag :action => 'reverse' do %>
<p>Text to reverse: <%= text_field_tag 'text_to_reverse' %> </p>
<p><%= submit_tag "Reverse!" %> </p>
<% end %>

Paul Krause  Dec 03, 2009 
Printed Page 34
Chapter3Controller

"sleep" takes a time in seconds as an argument. The printed version of get_time will generate an error (in Ruby 1.9 at least). I think it should be corrected to:
def get_time
sleep 1
render :text => Time.now
end

Paul Krause  Dec 02, 2009 
Printed Page 25
Update with Ajax.Updater example

Again, the default method for Ajax.Updater is 'post'. This needs to be sent as a 'get' request, so the options hash {method:'get' } needs to be appended to the arguments.

Paul Krause  Dec 02, 2009 
Printed Page 24
Call with Prototype example

The default method for Ajax.Request is 'post'. This needs to be sent as a 'get' request, so method:'get' needs to be included in the options hash.

Paul Krause  Dec 02, 2009 
2.2
First code block

In the first code block, the current version of rails enforces security with an authentication token. The default call produced here is a post which triggers an InvalidAuthenticityToken error.

<p><a href="#" onclick="prototypeAlert( );">Call with Prototype</a></p>
<script type="text/javascript">
function prototypeAlert( ) {
new Ajax.Request('/chapter2/myresponse', { onSuccess: function(request) {
alert(request.responseText);
}})
}
</script>

It is easily fixed by adding "method: 'get'," to the new Ajax.Request call, like this:

<p><a href="#" onclick="prototypeAlert( );">Call with Prototype</a></p>
<script type="text/javascript">
function prototypeAlert( ) {
new Ajax.Request('/chapter2/myresponse', { method: 'get', onSuccess: function(request) {
alert(request.responseText);
}})
}
</script>

Wayne Andersen  Jan 31, 2009 
2.2
1st code sample

I called it serious, because the code just won't work in Rails 2.0

You need to add the form's authenticity token to the params before Rails 2.0 will accept it:

authenticity_token=<%= form_authenticity_token %>

I simply added this string after a "?" after 'myresponse' in line 6 of the sample code.

Anonymous  Oct 23, 2008 
Printed Page 34, 37
First example source on the page

The code only renders the time and one doesn't get a chance to click on a link. Thus, it seems to be an issue in the controller action on page 34:

def get_time

# This line generates an error message.
sleep 1.second

# This line just renders the text within the view time text in the
# without displaying the link.
render :text => Time.now

end

Thus, the code on page 37 fails to execute successfully.

Anonymous  May 21, 2008