我使用Rails 4.2.3并且我得到了“No route matches {:action =>" delete",:controller =>" my_objects&#34 ;,:id => 8}“当我访问包含以下链接的视图时出错
<%= link_to 'Delete',url_for(controller: 'my_objects', action: :delete,id: my_object_time.my_object.id),method: :delete, data: {confirm: "Are you sure you want to delete this data?"} %>
但是,在我的routes / config.rb文件中,我已经包含了
resources :my_objects
我甚至在my_objects_controller.rb文件中有方法......
def delete
my_object.find(params[:id]).destroy
format.html { redirect_to controller: "users", action: "index", notice: 'Delete successful.' }
end
所以我不确定为什么它全都崩溃了。任何帮助表示赞赏, - 戴夫
答案 0 :(得分:1)
试试这个:
<%= link_to 'Delete',url_for(controller: 'my_objects', action: :destroy,id: my_object_time.my_object.id),method: :delete, data: {confirm: "Are you sure you want to delete this data?"} %>
或
<%= link_to 'Delete', my_object_time.my_object.id, method: :delete, data: { confirm: 'Are you sure?' } %>