开发者

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

开发者 https://www.devze.com 2023-03-27 01:17 出处:网络
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.

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'开发者_如何学C, '>= 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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消