Triggering GET method on form submit when POST method is specified

157 views Asked by At

I have a form_tag to which I specify a POST method but each time I submit the form it is trying to use the GET method. Here is my form :

 <%= form_tag (refund_path(subscription), :method => "post") do %>
                  <%= hidden_field_tag :subscription_id_refund, subscription.id %>
                  <%= submit_tag "Rembourser ce joueur", id: "export", class: "btn btn-warning"%>
                  <% end -%>

here is my route :

 post 'refunds/:subscription_id', to: "subscriptions#refund", as: "refund"

here is my method :

def refund
    @subscription = Subscription.find(params[:subscription_id_refund])
    if mangopay_refund
      @subscription.status == "refused"
      redirect_to
      flash[:notice] = "Vous avez bien procéder au remboursemend de #{@subscription.user.full_name}. Celui-ci ne participe plus au tournoi"
    else
      redirect_to
      flash[:warning] = "Le remboursement n'a pas pu etre effectué. Merci de réessayer plus tard"
    end
  end

Do you know how to fix that ?

1

There are 1 answers

1
jon snow On

The method for the form defaults to POST.So remove :method => "post" options and try.

 <%= form_tag(refund_path(subscription)) do %>

Reference : form_tag