Fix Devise Turbo Stream responses for flash messages
CI / Test (pull_request) Successful in 33s
Release Drafter / Update release notes draft (pull_request) Successful in 2s

Wire Users::DeviseController as Devise parent controller with the
Turbo-aware responder, so failed form submissions (login, password
reset) render correctly as HTML with 422 status instead of
unprocessable turbo-stream content that Turbo silently drops.

Also fixes a NameError in the responder (rendering_options ->
error_rendering_options) and removes the dead TurboController.
This commit is contained in:
2026-08-10 16:37:01 -06:00
parent 8a8d407bcc
commit c79c421b89
3 changed files with 9 additions and 19 deletions
-18
View File
@@ -1,18 +0,0 @@
class TurboController < ApplicationController
class Responder < ActionController::Responder
def to_turbo_stream
controller.render(options.merge(formats: :html))
rescue ActionView::MissingTemplate => error
if get?
raise error
elsif has_errors? && default_action
render rendering_options.merge(formats: :html, status: :unprocessable_entity)
else
redirect_to navigation_location
end
end
end
self.responder = Responder
respond_to :html, :turbo_stream
end
+1 -1
View File
@@ -6,7 +6,7 @@ class Users::DeviseController < ApplicationController
if get?
raise error
elsif has_errors? && default_action
render rendering_options.merge(formats: :html, status: :unprocessable_entity)
render error_rendering_options.merge(formats: :html, status: :unprocessable_entity)
else
redirect_to navigation_location
end
+8
View File
@@ -6,6 +6,7 @@ require 'securerandom'
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# Hotwire/Turbo
config.parent_controller = 'Users::DeviseController'
config.responder.error_status = :unprocessable_entity
config.responder.redirect_status = :see_other
@@ -324,3 +325,10 @@ Devise.setup do |config|
# changed. Defaults to true, so a user is signed in automatically after changing a password.
# config.sign_in_after_change_password = true
end
# Turbo-aware responder for Devise controllers
ActiveSupport.on_load(:devise_controller) do
self.responder = Users::DeviseController::Responder
Users::DeviseController::Responder.error_status = :unprocessable_entity
Users::DeviseController::Responder.redirect_status = :see_other
end