当调用销毁记录不被从数据库中删除 [英] When calling destroy, record is not being removed from DB
本文介绍了当调用销毁记录不被从数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有打算摧毁一个记录中的link_to:
I've got a link_to meant to destroy a record:
<%= link_to 'Delete from DB', {:controller => 'foos', :action => 'destroy', :id => foo.id}, :class => "btn btn-primary btn-mini" %>
在控制器中的破坏方法:
The destroy method in the controller:
def destroy
@foo = Foo.find(params[:id])
@foo.destroy
respond_to do |format|
format.html { redirect_to :back }
format.json { head :no_content }
end
end
pressing按钮不会删除的记录,但如果我打开轨控制台和呼叫 .destroy
在现有FOO,它是从拆除DB。
Pressing the button doesn't delete the record, but if I open up rails console and call .destroy
on an existing foo, it is removed from the DB.
让我知道,如果你在这里看到一个错误。谢谢你。
Let me know if you see a mistake here. Thanks.
推荐答案
这可能是因为您发送 GET
的要求,而你需要发送删除
,以便调用破坏
操作请求。所以,你的链接应该是:
It's probably because you send GET
request while you need to sent DELETE
request in order to call destroy
action. So, your link should look:
<%= link_to 'Delete from DB', foo, :class => "btn btn-primary btn-mini", :method => 'delete' %>
这篇关于当调用销毁记录不被从数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文