Skip to content

Instantly share code, notes, and snippets.

@rbclark
Created August 9, 2022 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbclark/cb222873b13617f82792699193b49b91 to your computer and use it in GitHub Desktop.
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
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