【发布时间】:2016-09-24 22:55:21
【问题描述】:
我正在使用 Rails 4.2.3,当我访问我的查看包含以下链接的视图
<%= 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
所以我不确定它为什么会分崩离析。任何帮助表示赞赏, - 戴夫
【问题讨论】:
-
delete是正确的 HTTP 动词。不过,Rails 控制器操作需要调用destroy。
标签: ruby-on-rails ruby-on-rails-4 controller routes