app: fix JS redirection with Turbolinks disabled

When Turbolinks is enabled, a `redirect_to` in a `format: :js` request
will emit code that instructs Turbolinks to navigate to the page.
Turbolinks will then load the redirection target as HTML, and display
it.

But with Turbolinks disabled, the same `redirect_to` will instead
respond with a standard `302: redirect`. `Rails.ajax` will interpret
this redirect as "Please perform the same call again to the redirected
URL, in the same format" – and request our redirection target, but
using `format: :js`.


This breaks the "Publish procedure" button. In that case, we really want
the page to be navigated to. Add an explicit JS redirect, so that the
redirection occurs in HTML.
This commit is contained in:
Pierre de La Morinerie 2020-05-07 15:32:31 +00:00
parent b5f1d97629
commit 51cb3a04a3
2 changed files with 18 additions and 6 deletions

View file

@ -72,7 +72,7 @@ class Admin::ProceduresController < AdminController
@procedure.publish_or_reopen!(current_administrateur)
flash.notice = "Démarche publiée"
redirect_to admin_procedures_path
render js: "window.location='#{admin_procedures_path}'"
rescue ActiveRecord::RecordInvalid
render 'publish_validate', formats: :js
end