1

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:

  • application.js
  • jquery.min.js
  • jquery-ui.min.js
  • jquery.js
  • jquery-ui.js
  • jquery_ujs.js

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>

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm, ok. I thought perhaps the helpers would make some of it transparent. For example, the code generating the Ajax call is a call to remote_function(). I can't expect stuff like that to work after I switched to jQuery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.