我试图通过以下教程来完成此工作:
http://net.tutsplus.com/tutorials/javascript-ajax/using-unobtrusive-javascript-and-ajax-with-rails-3/
处的railscast
和http://railscasts.com/episodes/205-unobtrusive-javascript
..在这两种情况下我都是有同样的问题。控制器没有渲染 .js 模板(它回退到 .html),因为请求标头没有像应有的那样请求 javascript。
我正在使用来自 github 的 jquery ujs 和 jquery 1.4.4
“data-remote=true”属性被提供给表单,就像它应该的那样。但由于某种原因,这并没有修改请求。
如果我切换到prototype.js,它就可以工作(使用rails中的默认prototype.js和rails.js)。
我正在使用 Rails 3.0.0
任何建议表示赞赏。
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.
发布评论
评论(3)
浪费了一天时间...:-(
我发现当您生成新的 Rails 3 应用程序时,会在 public/javascripts 文件夹中创建一个名为rails.js 的文件以及您习惯在其中看到的所有其他 .js 文件Rails 2 项目
包含所有不显眼的处理程序,默认情况下,Rails 假定您使用的是 Prototype.js ,
请将文件rails.js 替换为 https://github.com/rails/jquery-ujs
下面的链接帮助了我:
http://www.simonecarletti.com/blog/ 2010/06/unobtrusive-javascript-in-rails-3/
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/
“当前”处理此问题的最佳方法是将这只小狗添加到您的 gemfile
https://github.com/ indirect/jquery-rails
run
然后
你就准备好了 - 当你运行生成器时它会覆盖默认的rails.js。
The "current" best way to handle this is to add this puppy to your gemfile
https://github.com/indirect/jquery-rails
run
then
then you're all set - it overwrites the default rails.js when you run the generator.
我遇到了类似的问题。然后,我决定因为问题出在 Ajax 上,所以我应该从一些非常简单的事情开始。所以,我从 这个
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