Multiple submits calling multiple methods in a single form

3

Hello! I have a form that contains two buttons, each button, when clicking, takes me to a different method inside the same controller. How do I do what needs to be done? Because I can not.

form

<%= form_tag (@portabilidade), method: :get, id: "form-motivo" do %>   <div class="form-group">
    <strong>Motivo</strong>
    <%= text_area_tag :motivo, @portabilidade.motivo, class: 'form-control' %>   </div>   <%= button_tag "Liberar", class: "btn btn-primary", id: "btn-liberar" %>   <%= button_tag "Reter", class: "btn btn-info", id: "btn-reter" %> <% end %>

Javascript

  $("#btn-reter").on("click", function () {
      e.preventDefault();
      $('#form-motivo').attr('action', "/reter");
      $("#form-motivo").submit();
  });

  $("#btn-liberar").on("click", function () {
      e.preventDefault();
      $('#form-motivo').attr('action', "/liberar");
      $("#form-motivo").submit();
  });

I get no error, just the URL changes and does not record, nor does it enter any of the methods.

My URL that was meant to be:

/portabilidades/:id/reter ou .../liberar

It was like this and did not work:

portabilidades/61?utf8=✓&motivo=erer&button=

Where is my error? Thanks!

    
asked by anonymous 16.05.2016 / 15:06

1 answer

0

You can use formaction

<button type="submit" formaction="/reter">Reter</button>
<button type="submit" formaction="/liberar">Liberar</button>

Here it worked exceptionally: D

    
16.05.2016 / 22:01