Skip to content

Instantly share code, notes, and snippets.

@ManickYoj
Last active January 22, 2024 12:04
Show Gist options
  • Save ManickYoj/57237b739cdf1a271c1b725e28ae9098 to your computer and use it in GitHub Desktop.
Save ManickYoj/57237b739cdf1a271c1b725e28ae9098 to your computer and use it in GitHub Desktop.
Devise Turbo Controller for Rails 7 Setup
# app/controllers/turbo_devise_controller.rb
class TurboDeviseController < 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment