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

Make Devise.mappings work with lazy loaded routes. #5728

Merged
merged 1 commit into from
Nov 24, 2024
Merged

Conversation

nashby
Copy link
Collaborator

@nashby nashby commented Nov 24, 2024

Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments. However, Devise's mappings are built during the routes loading phase. To ensure it works correctly, we need to load the routes first before accessing @@mappings.

Closes #5705 #5695

Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.
However, Devise's mappings are built during the routes loading phase.
To ensure it works correctly, we need to load the routes first before accessing @@mappings.
@nashby nashby merged commit 591b03a into main Nov 24, 2024
40 of 42 checks passed
@nashby nashby deleted the lazy-routes-fix branch November 24, 2024 17:06
@kjellberg
Copy link

When can we expect a release with this? Thanks

@jrochkind
Copy link

jrochkind commented Dec 4, 2024

Main branch is labelled devise version 5.0.0-beta. I'm not sure the release plan/schedule, or what changes/backwards compat might be included in forthcoming devise 5.

But would it be possible to backport this to a devise 4.x branch and do a 4.x release with it? I too believe I am blocked from a Rails 8 upgrade on this.

@jrochkind
Copy link

jrochkind commented Dec 12, 2024

Converting this PR to this patch in a config/initializers/devise_rails8_patch.rb file seems to let me get going with Rails 8 and devise 4.9.4.

  require 'devise'
  Devise # make sure it's already loaded

  module Devise
    def self.mappings
      # Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.
      # However, Devise's mappings are built during the routes loading phase.
      # To ensure it works correctly, we need to load the routes first before accessing @@mappings.
      Rails.application.try(:reload_routes_unless_loaded)
      @@mappings
    end
  end

mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this pull request Dec 14, 2024
mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this pull request Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Rails 8: test helpers do not work
3 participants