mardi 9 novembre 2021

Problem with remote Button method post to redirect in controller

My problem: When place is not present controller does not redirect to the route i want.

I have a link_to , check_payer post route

<%= link_to "Click here", check_payer_path, method: :post, remote: true %>

this methods verify if place is present and if true is not redirecting to billings_path

  def check_payer
    if @place.present?
      redirect_to billings_path
    end
  end

If place is not present it will render check_payer.js.erb that opens a form modal.

$('#modal-check-payer').find(".modal-content").html("<%= j render partial:'place_billing_infos/check_payer_modal' %>");
$("#modal-check-payer").modal();

And this nested form call update_payer_path patch.

<%= simple_nested_form_for @place_billing_info, url: update_payer_path, html: { 
autocomplete: 'off', class: "form-horizontal" } do |place_form| %>

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span 
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel"><%= html_icon_member %> <span class="text- 
normal">Insira seu CPF/CNPJ para visualizar a fatura.</span></h4>
</div>

 <div class="modal-body">
 <div class="row">
  <div class="col-sm-12 text-muted">
    <%= place_form.simple_fields_for :billing_info do |info| %>
      <div class="col-md-4  col-xs-8 modal-text-left"><%= info.input :payer_cpfcnpj, 
 wrapper: :default_form, label: 'Cpf/Cnpj', required: true %></div>
     <% end %>
   </div>
 </div>
</div>

<div class="modal-footer">
<button type="submit" class="btn btn-info new-member-submit">Exibir fatura</button>
</div>
<% end %>

Aucun commentaire:

Enregistrer un commentaire