Search code examples
rubyruby-on-rails-3.1formtastic

Specify HTML method in Formtastic action link


In a Formtastic semantic_form_for, I want the Cancel link to point to the destroy action of a controller via the delete method:

= semantic_form_for @user, url: password_reset_path(params[:id]) do |f|
    = f.inputs do
        = f.input :password
        = f.input :password_confirmation
    = f.actions do
        = f.action :submit, label: 'Reset password'
        = f.action :cancel, label: 'Cancel password reset',
            as: :link, url: password_reset_path(params[:id]), html: { method: :delete }

It is the html: { method: :delete } part that I would like to get to work, so that my temporary resource "password reset" is immediately destroyed via password_resets#destroy when the user clicks on the Cancel link.

Note that this is not about specifying the HTML method for the entire form (as has been asked elsewhere).

The above code ignores the DELETE method, so that I wonder how I can accomplish this?


Solution

  • Use button_html option.

    Try it!

    <%= f.action :cancel, :label => "Cancelar", url: order_path(@order), button_html: {method: :delete} %>