ruby-on-rails – 为什么Rails“link_to”不适用于删除操作?
发布时间:2020-12-16 21:55:15 所属栏目:百科 来源:网络整理
导读:在index.html.erb中,我显示所有产品,每个产品旁边都有“编辑”和“删除”操作: % @products.each do |product| % ... %= link_to("Edit",edit_product_path(product.id),:class = 'action') % %= link_to("Delete",product,:method = :delete,:class = 'act
在index.html.erb中,我显示所有产品,每个产品旁边都有“编辑”和“删除”操作:
<% @products.each do |product| %> ... <%= link_to("Edit",edit_product_path(product.id),:class => 'action') %> <%= link_to("Delete",product,:method => :delete,:class => 'action') %> ... <% end %> 编辑链接工作正常.但是,删除链接不起作用.我收到以下错误: Unknown action The action 'show' could not be found for ProductsController 我猜是因为request方法是GET而不是DELETE.但是,如果我明确设置,我不知道为什么会发生这种情况:method => :删除. routes.rb很简单: root :to => "products#index" resources :products 我启用了Javascript 请建议. 解决方法
你有一个javascript_include_tag中指定的rails.js吗?这是非常显着的DELETE方法工作所必需的.如果你使用jQuery,那么有一个
solution for that too.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |