From d447d10b6e7933d361bbded679f7f34203ebb892 Mon Sep 17 00:00:00 2001 From: Eugen Kuksa Date: Fri, 1 Sep 2017 17:22:13 +0200 Subject: [PATCH] Don't add devise routes if running DB rake tasks. --- Gemfile.lock | 2 +- config/routes.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 92fc53b8..1287fe93 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: git://github.com/ontohub/ontohub-models.git - revision: 5c43e364fd84c2022361f72e44cceb4a126e0eb7 + revision: a4c8d67e63bdd02d14a4cfb9a118ada143b41f22 branch: master specs: ontohub-models (0.1.0) diff --git a/config/routes.rb b/config/routes.rb index bff377d4..2743933e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,8 +43,14 @@ def allow_double_slashes_in_routes allow_double_slashes_in_routes do scope format: false, defaults: {format: :json} do # Add mappings for Devise, but skip all Devise-routes - devise_for :users, - skip: %i(registrations confirmations sessions unlocks passwords) + # We exclude these Devise mappings from these rake tasks because they + # load the models. When loading the models, the database needs to exist, + # or else it throws an error. + unless rake_task?(%w(db:create db:migrate db:drop + db:recreate db:recreate:seed)) + devise_for :users, + skip: %i(registrations confirmations sessions unlocks passwords) + end # Add routes to a no-op action to create URL-helpers that are used in # confirmation, password-reset and unlock emails