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_path, method: :post, remote: true %>
this methods verify if place is present and if true is not redirecting to other_path
CodePudding user response:
Because of remote: true
the request will come in as xhr
and render check_payer.js.erb
. This .js.erb
contains something that the browser knows how to interpret/execute.
In your scenario when the redirect happens, the browser doesn't know what to do with the response. If you open the browser console (or Inspector) in Network
tab you will see it makes a redirect to billings_path
.
To handle both scenarios you need to handle everything inside check_payer.js.erb
.
# check_payer.js.erb
<% if @place.present? %>
window.location = "<%= billings_path %>"
<% else %>
$('#modal-check-payer').find(".modal-content").html("<%= j render partial:'place_billing_infos/check_payer_modal' %>");
$("#modal-check-payer").modal();
<% end %>