Ruby Rails: Ajax is not defined error …

This has been a little tricky. I have followed a nice Ajax tutorial for rails but i kept getting the “Ajax is not defined” error in the javascript console. The solution is to include the prototype.js javascript file into your code. Simply write the following into your rhtml file:

 <%= javascript_include_tag "prototype" %>

That’s all.

8 thoughts on “Ruby Rails: Ajax is not defined error …”

  1. Hey dude,

    Thanks for this tip – but….
    Isn’t scriptaculous integrated into Ruby? why do we have to define it? that’s what I wondered.

  2. but i thought for prototype to be used in any rhtml/jsp, one definitely has to include the javascripts in the head. does “prototype integrated into rails” mean we can use like a default library without including it???

  3. From what i figured out no, you can’t use it directly. Prototype ingrated means that they use prototype in their code,
    so you don’t have to download prototype separately and put it in your code, you only have to include it they way it’s on the post.

  4. Hi, I tried it but for me still it is saying Ajax is not defined. I have invoked a popup window and from there now i am calling a javascript method that should then call an ajax method, but it says Ajax is not defined. Any clues??

  5. Have you added the above mentioned
    < %= javascript_include_tag "prototype" %>
    in the rhtml file that displays the contents of your popup?

  6. prototype.js should be included when you add But I’m still getting the same error.
    The most wierd thing is that the error is raise when the application runs on mod_rails, but if the application runs on mongrel everything works just fine

Comments are closed.