嘿,我已经看过几篇关于这个的帖子了,但我仍然在调用:方法=>‘=>’并被定向到我的控制器的show方法时遇到问题。destroy方法按照预期工作,因为它删除了注释,但在请求完成后,它在GET上抛出一个404。代码如下:
<%= link_to 'delete', "/events/#{@event.id}/comments/#{comment.id}.js",
:confirm => 'Are you sure?',
:method => :delete,
:remote => true %>下面是控制器方法:
def destroy
@comment = @event.comments.find(params[:id])
@comment.destroy
redirect_to do |format|
format.html # redirect_to @event, :notice => "comment deleted" }
format.js { render 'destroy.js.erb' }
end
end我听说这可能是因为没有使用button_to,但我尝试使用button_to而不是link_to,但这是同样的事情。
我还听说这可以解决你在设置中使用jquery的一些问题,但我觉得我对此表示怀疑,但以下是我调用jquery以防万一(application.html.erb)的方法:
<%= javascript_include_tag 'jquery-1.5.2.min.js', 'rails', 'application' %>
<%= javascript_include_tag 'jquery-ui-1.8.17.custom.min.js' %>当我观察rails服务器的输出时,我看到它是这样说的:
Redirected to http://0.0.0.0:3000/events/1/comments/35
Completed 302 Found in 132ms
ACTION NAME application
Started GET "/events/1/comments/35" for 127.0.0.1 at Wed Feb 08 16:31:43 -0800 2012
AbstractController::ActionNotFound (The action 'show' could not be found for CommentsController):谢谢你的帮助!
发布于 2013-06-05 08:11:46
Rails 3.1和更高版本在很大程度上消除了us...rails.js的这一缺陷。Jquery_ujs是gem的一部分,但是该文件不应该在您的javascript目录中:具体地说,我的jquery_ujs文件很旧,仍然“存活”在我的assets/javascript目录中。它仍然有.live方法,这些方法已被弃用。删除文件!!
保留gem ' jquery -rails',‘REF 2.1’#~>:https://github.com/rails/jquery-ujs保留//= require_tree和//= require jquery_ujs和//= require_tree。在您的application.js文件中,确保更新gem和bundle安装,以获得最新的gem。如果抛出一个javascript错误,就像我遇到的“偷偷摸摸”的情况一样,剩下的link_to js将无法工作。现在,删除和确认对话框工作正常。罪魁祸首是一部老旧的jquery_ujs。
https://stackoverflow.com/questions/9203827
复制相似问题