devise icon indicating copy to clipboard operation
devise copied to clipboard

rails 7 integration guide?

Open mices opened this issue 3 years ago • 4 comments

Is there an integration guide for rails 7?

mices avatar Aug 06 '22 12:08 mices

@mices , you want an integration guide for rails 7 with devise?

suryanarayanan035 avatar Aug 06 '22 16:08 suryanarayanan035

yes because i get the following error: -0400 Rack app ("GET /" - (127.0.0.1)): #<LoadError: cannot load such file -- /home/.../.rvm/gems/ruby-3.0.1/gems/turbo-rails-1.1.1/app/channels/turbo/streams>

mices avatar Aug 06 '22 16:08 mices

Watch issue https://github.com/heartcombo/devise/issues/5446. This article provides a good workaround.

Yenwod avatar Aug 10 '22 10:08 Yenwod

I think the solution is to run rails turbo:install:redis I got stuck on something else on the same app so I haven't had a chance to try it yet

mices avatar Aug 11 '22 03:08 mices

The article and GoRails referenced fixes referenced are excellent. Based on my experience, it does not solve for account cancellation. I fixed it here:

# TurboDeviseController::Responder.to_turbo_stream rescue block
        if has_errors? && default_action
          render rendering_options.merge(formats: :html, status: :unprocessable_entity)
        # this is the condition added to handle user account cancellation
        elsif @controller.controller_name == "registrations" && @controller.action_name == "destroy"
         # avoid missing template after user destruction
          redirect_to "/"
        else
          redirect_to navigation_location
        end

You also need to modify the view so it doesn't blow past the confirm with form: { data: { turbo_confirm: "Are you sure?" }

devise/registrations/edit.html.erb

  <p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), form: { data: { turbo_confirm: "Are you sure?" } }, method: :delete %></p>

msducheminjr avatar Nov 12 '22 22:11 msducheminjr

Watch issue #5446. This article provides a good workaround.

We were using this fix in our repository too, but responders bumped to v3.1.0 which changed rendering_options to error_rendering_options, so you have to just replace the variable name in the TurboDeviseController to get it working:

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 error_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

gazayas avatar Feb 08 '23 11:02 gazayas

Hey all, please checkout https://github.com/heartcombo/devise/pull/5548, we're wrapping up the changes to make Devise compatible with Turbo, which shouldn't require those additional overrides / workarounds. Hopefully that should all work out of the box, but if you run into any issues, let us know. That should be merged to main soon too.

carlosantoniodasilva avatar Feb 08 '23 12:02 carlosantoniodasilva