我的 Ajax 试图渲染一个不应该的视图
所以一切正常。但是如果用户打开 Firebug 的控制台,他们就会看到一个错误。 :D
当我的 AJAX 发送时:
$(".remove_qf").live("click", function(){
$.ajax({type: "POST", url: $(this).attr("href"), data: { '_method': 'delete' }, dataType: "script"});
return false;
})
我的控制器触发它:
def destroy
@quick_fact = @organization.quick_facts.find(params[:id])
@quick_fact.destroy
end
一个视图被触发并在 500 上出错:
Missing template quick_facts/destroy.erb in view path app/views:vendor/plugins/rails-ckeditor/app/views
但很奇怪,因为我不需要销毁视图,而且我不应该向我拥有的内容添加任何代码已经告诉它渲染 false。我这样说是因为我有类似的工作在相同的前提下进行。
有谁知道可能是什么原因造成的?
更新
Routes.rb
map.resources :organizations,
:collection => {:live_validation => :post, :search => :get, :send_invitation_code_request => :post} do |organization|
organization.resources :quick_facts
So everything works. But if a user has firebug's console open, they'll see a bug. :D
When my AJAX is sent :
$(".remove_qf").live("click", function(){
$.ajax({type: "POST", url: $(this).attr("href"), data: { '_method': 'delete' }, dataType: "script"});
return false;
})
And my controller fires it :
def destroy
@quick_fact = @organization.quick_facts.find(params[:id])
@quick_fact.destroy
end
A view is fired and errors out on a 500 :
Missing template quick_facts/destroy.erb in view path app/views:vendor/plugins/rails-ckeditor/app/views
Strange though, because I don't need a destroy view, and I shouldn't add any code to what I have already to tell it to render false. I say this because I have something similar working my project with the same premise.
Anyone know what might be causing this?
Update
Routes.rb
map.resources :organizations,
:collection => {:live_validation => :post, :search => :get, :send_invitation_code_request => :post} do |organization|
organization.resources :quick_facts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是这方面的专家,但是,我认为 1.) 您需要在 ajax 调用中添加一个处理程序来确定删除是否成功& 2.) 您可能需要从控制器的销毁操作中添加某种成功状态消息。
I am not an expert in this area, however, I think that 1.) you need to add a handler to your ajax call to determine if the delete was successful & 2.) you may need to add some sort of success status message from the controller's destroy action.
以下内容为我解决了同样的问题。
我不确定这是否比使用 render :nothing => 更好。 true 或
render :text => “”
。The following solved the same problem for me.
I'm unsure if this is better practice than using
render :nothing => true
orrender :text => ""
.