我的 Rails 应用程序中有一个模型类别。根据 rails RESTful Routes,我可以对模型执行 CRUD 操作,在我的 routes.rb 中定义了 resources: categories
。
但是我如何在我的 View 中定义 destroy path helper 来执行 DELETE
操作,就像 edit_category_path(@category)
编辑记录一样。我这样试过
destroy_category_path(@category)
但出现错误
undefined method `destroy_category_path' for #<#<Class:0x00000005371298>:0x000000053734f8>
最佳答案
该路径与显示操作 ( '/categories/:id' ) 完全相同,但您还需要指定 DELETE
HTTP method :
button_to @category, method: :delete
请注意,使用具有破坏性/建设性行为的链接被认为是不安全的,因为机器人可能会访问这些链接。
关于ruby-on-rails - 如何在我的 Rails 应用程序 View 中指定销毁路径助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26047296/