Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails 7 integration guide? #5513

Closed
mices opened this issue Aug 6, 2022 · 7 comments · Fixed by #5548
Closed

rails 7 integration guide? #5513

mices opened this issue Aug 6, 2022 · 7 comments · Fixed by #5548

Comments

@mices
Copy link

mices commented Aug 6, 2022

Is there an integration guide for rails 7?

@suryanarayanan035
Copy link

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

@mices
Copy link
Author

mices commented Aug 6, 2022

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>

@Yenwod
Copy link
Contributor

Yenwod commented Aug 10, 2022

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

@mices
Copy link
Author

mices commented Aug 11, 2022

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

@msducheminjr
Copy link

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>

carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
@gazayas
Copy link

gazayas commented Feb 8, 2023

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

@carlosantoniodasilva
Copy link
Member

Hey all, please checkout #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

6 participants