Problem with AJAX and UJS with jQuery in Rails 3
I am trying to get this working by following the tutorial at:
http://net.tutsplus.com/tutorials/javascript-ajax/using-unobtrusive-javascript-and-ajax-with-rails-3/
and the railscast at
http://railscasts.com/episodes/205-unobtrusive-javascript
..in both cases I am having the same problem. The controller is not rendering the .js template (it is falling开发者_运维知识库 back to .html) because the request header isn't requesting javascript like it should be.
I am using the jquery ujs from github and jquery 1.4.4
The "data-remote=true" attribute is being supplied to the form like it is supposed to be. But for some reason this isn't modifying the request.
If I switch to prototype.js it works (with the default prototype.js and rails.js from rails).
I am using rails 3.0.0
Any suggestions appreciated.
After wasting a day...:-(
I found that When you generate a new Rails 3 application, a file called rails.js is created in the public/javascripts folder along with all the other .js files you are used to see in a Rails 2 project.
rails.js contains all the unobtrusive handlers. By default, Rails assumes you are using Prototype.js .
For Jquery replace the file rails.js with https://github.com/rails/jquery-ujs
The below link helped me: http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
The "current" best way to handle this is to add this puppy to your gemfile
https://github.com/indirect/jquery-rails
run
bundle install
then
rails generate jquery:install #--ui to enable jQuery UI --version to install specific version of JQuery (default is 1.4.2)
then you're all set - it overwrites the default rails.js when you run the generator.
I had similar issues.Then, i decided since the problem was with Ajax, i should start with something very simple.So, i started with This
精彩评论