简体   繁体   English

如何在 simple_form 中使用多个 HTTP 方法?

[英]How can I use multiple HTTP methods in simple_form?

I have a view like this:我有这样的看法:

= simple_form_for @fixed_number, url: polymorphic_path([:manage, @numberable, :fixed_number]), method: :put do |f|
  = f.input :number
  = f.submit 'Ok', class: "btn btn-success"
  = f.button :button, "Delete", class: "btn btn-danger", method: :delete

Obviously I want that Delete button to send the DELETE method.显然我希望删除按钮发送 DELETE 方法。 It doesn't work - it uses the PUT specified for the whole form.它不起作用 - 它使用为整个表单指定的 PUT。 Can I have one form that changes method for a particular button?我可以有一个表单来更改特定按钮的方法吗?

I found a solution.我找到了解决方案。 I don't know if it's the best one.不知道是不是最好的In particular it relies on UJS and CSS.特别是它依赖于 UJS 和 CSS。 I replaced the delete button with a styled link:我用样式链接替换了删除按钮:

  = link_to "Delete", f.options[:url], method: :delete, class: "btn btn-danger"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM