Create Devise routes only when 'users' table exists

Closes #42
This commit is contained in:
cryptogopher 2025-07-25 15:30:26 +02:00
parent 5ffc6974f0
commit da38d8b585
2 changed files with 10 additions and 3 deletions

View File

@ -19,7 +19,8 @@ class User < ApplicationRecord
validates :email, presence: true, uniqueness: true,
length: {maximum: type_for_attribute(:email).limit}
validates :unconfirmed_email, length: {maximum: type_for_attribute(:unconfirmed_email).limit}
validates :unconfirmed_email,
length: {maximum: type_for_attribute(:unconfirmed_email).limit}
def to_s
email

View File

@ -20,8 +20,14 @@ Rails.application.routes.draw do
end
end
devise_for :users, path: '', path_names: {registration: 'profile'},
controllers: {registrations: :registrations}
# Devise does not handle properly models that require database access during loading.
# https://github.com/heartcombo/devise/issues/5786
connection = ActiveRecord::Base.connection
if connection.schema_version && connection.table_exists?(:users)
devise_for :users, path: '', path_names: {registration: 'profile'},
controllers: {registrations: :registrations}
end
resources :users, only: [:index, :show, :update] do
member { get :disguise }
collection { get :revert }