rogerkk
rogerkk

Reputation: 5695

Rails 3 project, installed jquery-rails gem, but getting "Ajax is not defined"

I'm a rails newbie trying to follow a howto on how to perform some Ajax calls (after switching to jQuery), but I've run into a problem.

Whenever I trigger the ajax code (new Ajax.Request()), I get "Ajax is not defined" in firebug. Anyone with more skills than me know what's up here?

update:

For anyone else having this problem, the code that was generating the the above code, was a call to remote_function()


What I have done to set things up:

  1. Added "gem 'jquery-rails', '>= 1.0.12'" to my gemfile, and run bundle install
  2. Run rails generate jquery:install

My public/javascripts/ folder thus has the following files:

The scripts included in my HTML look like this:

<script src="/javascripts/jquery.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/jquery-ui.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/jquery_ujs.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/application.js?1312911234" type="text/javascript"></script>

Upvotes: 1

Views: 1002

Answers (1)

mu is too short
mu is too short

Reputation: 434585

I'd guess that your tutorial uses Prototype as Ajax.Request is for Prototype, you should be using $.ajax with jQuery. And switching to a jQuery based tutorial might be a good idea too.

You say that you're using remote_function but that's Prototype-specific:

Usage
To be able to use these helpers, you must first include the Prototype JavaScript framework in your pages.

Prototype used to be the default JavaScript library for Rails so I suspect that PrototypeHelper is a leftover. You probably want to look at things like the :remote option on link_to and similar for new code.

Upvotes: 5

Related Questions