Your Teacher
Chris Oliver
Hi, I'm Chris. I'm the creator of GoRails, Hatchbox.io and Jumpstart. I spend my time creating tutorials and tools to help Ruby on Rails developers build apps better and faster.
About This Episode
Hotwire's Turbo library intercepts forms automatically so Devise needs a few tweaks to work with it. Learn how to do that in this screencast!
Notes
Resources
Code
# config/initializers/devise.rb
# frozen_string_literal: true
class TurboFailureApp < Devise::FailureApp
def respond
if request_format == :turbo_stream
redirect
else
super
end
end
def skip_format?
%w(html turbo_stream */*).include? request_format.to_s
end
end
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
Devise.setup do |config|
# ==> Controller configuration
# Configure the parent class to the devise controllers.
config.parent_controller = 'TurboController'
# ==> Warden configuration
config.warden do |manager|
manager.failure_app = TurboFailureApp
end
end
Hotwire
0% Complete
1
How to use Hotwire in Rails
24m
How to use Devise with Hotwire & Turbo.js
11m
3
How to upgrade from Turbolinks to Hotwire & Turbo
11m
4
Hotwire Modal Forms
8m
5
Flash Messages and Toasts with Hotwire & Turbo.js
11m
6
Dynamic Select Fields in Rails with Hotwire
19m
7
Datatables From Scratch Using Hotwire
25m
8
Migrating from Rails UJS to Hotwire: Data Method, Confirm, and Disable With
12m
9
Realtime Charts with Stimulus Target Callbacks
13m
10
Inline Editing with Turbo Frames in Rails
20m
11
Custom Turbo Confirm Modals with Hotwire in Rails
9m
12
Dynamic Nested Forms with Turbo
31m
13
Turbo Confirm Modals with Confirmation Text in Rails
15m
14
Auto-submitting Forms & Custom Turbo Stream Actions
10m
15
Custom Turbo Stream Actions
15m
16
Refactoring Turbo Streams into Turbo Frames
10m
17
Dynamic Nested Forms With Turbo Part 2
35m
18
Responsive Navigation with Turbo
12m