You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When rendering a form with remote: true, one can replace the form with an error-rendered state via AJAX. However, using the very popular "responders" conventions, like Devise does, you find that the success response looks like:
The problem here being that the turbolinks-rails handling of the redirection in the success case never happens. In fact, no attempt at redirection is made. It simply tries to render a JS template for the action.
I'm not sure if a fix really belongs inside turbolinks-rails, but this issue is of course specific to turbolinks-rails. So if anyone else is pondering about the same problem, here's a simple fix:
# config/initializers/responders.rb
module ActionController
class Responder
# Default implementation of `to_js` is just `default_render` but if there's no errors and
# we pass a location then I expect to be redirected via Turbolinks JS
def to_js
if !has_errors? && options[:location].present?
redirect_to options[:location]
else
default_render
end
end
end
end
When rendering a form with
remote: true, one can replace the form with an error-rendered state via AJAX. However, using the very popular "responders" conventions, like Devise does, you find that the success response looks like:while the error response looks like
The problem here being that the turbolinks-rails handling of the redirection in the success case never happens. In fact, no attempt at redirection is made. It simply tries to render a JS template for the action.
I'm not sure if a fix really belongs inside turbolinks-rails, but this issue is of course specific to turbolinks-rails. So if anyone else is pondering about the same problem, here's a simple fix: