From da38d8b5856fe410e62dcbcfdb2e6e0d28374431 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Fri, 25 Jul 2025 15:30:26 +0200 Subject: [PATCH] Create Devise routes only when 'users' table exists Closes #42 --- app/models/user.rb | 3 ++- config/routes.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 60e9df1..f113f3b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index b40d356..6218a39 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 }