我至少有以下不起作用的链接
= 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>
路由.rb
namespace :admin do
#...
resources :pictures do # admin/pictures
member do
put 'set_show'
put 'set_shown'
end
resources :comments, :only => [:destroy]
end
end
应用程序.html.haml
%html
%head
%title title
= stylesheet_link_tag :application
= javascript_include_tag :application
= csrf_meta_tag
应用程序.js
//= 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 应用程序升级时遇到了这个错误,我可能会丢失什么会导致这个错误。