September 30, 2007

pique.rhtml example in Ajax on Rails is missing some important details

As the first example of using Ajax on Rails, the example on page 4 chapter 1 is sorely lacking some important details to get the demonstration to work.

The code for whet.rjs is correct and does not need to be changed. However, it needs to be located in app/views/pique

What was that? You weren’t told to create a rails project? Better skip on down to page 19 chapter 2.

rails myproject

cd myproject

Then generate the controller ruby script/generate controller pique pique

The file pique.rhtml also goes in app/views/pique

start server ruby myproject/script/server

http://hostname:3000/pique/pique

WHAT! it doesn’t work?

you need to add

<%= javascript_include_tag ‘prototype’ %>
<%= javascript_include_tag ‘effects’ %>

to the top of pique.rhtml

without prototype, the javascript is not executed and is instead displayed back to you in the browser

you will get something like:

try {
$("greeting").hide();
$("greeting").update("Greetings, df");
$("greeting").visualEffect("grow");
$$("form").first().reset();} catch (e)
{ alert('RJS error:nn' + e.toString());
alert('$(\"greeting\").hide();
n$(\"greeting\").update(\"Greetings, df\");
n$(\"greeting\").visualEffect(

without effects you will get:

RJS error:

TypeError: $(“greeting”).visualEffect is not a function

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.