简体   繁体   中英

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. It doesn't work - it uses the PUT specified for the whole form. 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. I replaced the delete button with a styled link:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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