Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Can';t创建用于删除的按钮\u_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails Can';t创建用于删除的按钮\u

Ruby on rails Can';t创建用于删除的按钮\u,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我有以下资源: 资源:文章 由于某种原因,我找不到方法delete的路径。我需要为按钮_to执行此操作 #from pry Rails.application.routes.url_helpers.articles_path("432432", {method: :delete}) # => "/articles/432432?method=delete" Rails.application.routes.url_helpers.articles_path(id: "432432"

我有以下资源:

资源:文章

由于某种原因,我找不到方法delete的路径。我需要为
按钮_to
执行此操作

#from pry

 Rails.application.routes.url_helpers.articles_path("432432", {method: :delete}) # => "/articles/432432?method=delete"

 Rails.application.routes.url_helpers.articles_path(id: "432432", method: :delete)
=> "/articles/432432?method=delete"

 Rails.application.routes.url_helpers.articles_path({ controller: :articles, action: :delete, id: "432432"})
=> "/articles?action=delete&id=432432"

# and so on...
按钮也是这样:

 <%= button_to 'Destroy', { controller: :articles, action: :delete, id: 'some_id' }, method: :delete, data: { confirm: 'Are you sure?' } %>

在rails4中,当使用
资源时,它肯定是
销毁
方法,而不是
删除

rails3也是如此:

因此,这应该是可行的:

 <%= button_to 'Destroy', { controller: :articles, action: :destroy, id: 'some_id' }, method: :delete, data: { confirm: 'Are you sure?' } %>


即使方法的真实名称是delete?控制器操作被称为
destroy
delete
指的是HTTP方法delete。如果您在控制器中实现了一个delete函数,并且想要使用它,您必须为它定义一个路由<代码>参考资料:文章
仅定义指南中规定的路线。使用按钮中的
action::destroy
将调用继承的
destroy
函数,而不是您的
delete
函数。
 <%= button_to 'Destroy', { controller: :articles, action: :destroy, id: 'some_id' }, method: :delete, data: { confirm: 'Are you sure?' } %>