Created
August 9, 2022 19:57
-
-
Save rbclark/cb222873b13617f82792699193b49b91 to your computer and use it in GitHub Desktop.
Improvement on the GoRails Turbo Controller which fixes an issue with the destroy method not redirecting properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DeviseTurboController < ApplicationController | |
class Responder < ActionController::Responder | |
def to_turbo_stream | |
if @default_response | |
@default_response.call(options.merge(formats: :html)) | |
else | |
controller.render(options.merge(formats: :html)) | |
end | |
rescue ActionView::MissingTemplate => error | |
if get? | |
raise error | |
elsif has_errors? && default_action | |
render rendering_options.merge(formats: :html, status: :unprocessable_entity) | |
else | |
navigation_behavior error | |
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