我至少有以下不起作用的链接
= link_to 'Delete', admin_picture_comment_path(comment.picture_id,comment.id), :class => 'delete', :remote => true ,:method => :delete
= link_to 'Disable', set_shown_admin_picture_path(picture), :class => 'delete', :method => :put, :remote => true
= link_to 'show', set_show_admin_picture_path(picture), :class => 'delete', :method => :put, :remote => true
= link_to 'delete', admin_picture_path(picture), :confirm => 'Are you sure?', :class => 'delete', :method => :delete, :remote => true
正在创建的HTML看起来正确
<a href="/admin/pictures/27/comments/25" class="delete" data-method="delete" data-remote="true" rel="nofollow">Delete</a>
<a href="/admin/pictures/27/set_shown" class="delete" data-method="put" data-remote="true" rel="nofollow">Disable</a>
在所有情况下,我都会找回类似
的内容没有路线匹配 [GET] “/ admin / pictures / 27 / comments / 23”
我认为这是因为jquery_ujs没有正确加载,但是我不知道为什么它没有加载,因为它显示在html标题中
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.fileupload.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.fileupload-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.lightbox.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
namespace :admin do
#...
resources :pictures do # admin/pictures
member do
put 'set_show'
put 'set_shown'
end
resources :comments, :only => [:destroy]
end
end
%html
%head
%title title
= stylesheet_link_tag :application
= javascript_include_tag :application
= csrf_meta_tag
//= require jquery
//= require jquery_ujs
//= require jquery.fileupload
//= require jquery.fileupload-ui
//= require jquery.lightbox
$(function(){
$('.admin_picture a.delete').live('ajax:success',function(){
$(this).closest('.admin_picture').fadeOut();
});
$('tr .ajax_delete').live('ajax:success', function() {
$(this).closest('tr').fadeOut();
});
$('.comment a.delete').live('ajax:success',function(){
$(this).closest('.comment').slideUp();
});
//...
});
gem 'rails', '3.2.9'
gem 'thin'
gem 'jquery-rails'
gem 'haml-rails'
#...
我从使用不显眼的jquery的rails 3.0应用程序升级时遇到了这个错误,我可能会错过什么会导致这种情况。
答案 0 :(得分:0)
具体来说,我的jquery_ujs文件很旧并且仍然“存在”我的assets / javascript目录中。它仍然有不推荐使用的.live方法。删除文件!!
保持宝石'jquery-rails','〜&gt; 2.1'#REF:https://github.com/rails/jquery-ujs
保持// = require jquery和// = require jquery_ujs和// = require_tree。
在您的application.js文件中
确保更新gem和bundle install以获取最新的gem。
如果抛出javascript错误,就像我的“偷偷摸摸”的情况一样,其余的link_to js将无效。