简体   繁体   中英

Rails: User does not respond to 'devise' method” when running “rails generate devise:install"

I have been working on this issue for hours now and haven't seemed to find anything exactly like this on StackOverflow.

   C:\Sites\isawyou>rake db:migrate
    rake aborted!
    User does not respond to 'devise' method. This usually means you haven't loaded
    your ORM file or it's being loaded too late. To fix it, be sure to require 'devi
    se/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your applicati
    on definition in 'config/application.rb'
    C:/Sites/isawyou/config/routes.rb:2:in `block in <top (required)>'
    C:/Sites/isawyou/config/routes.rb:1:in `<top (required)>'
    C:2:in `rescue in execute_if_updated'
    C:in `execute_if_updated'
    C:/Sites/isawyou/config/environment.rb:5:in `<top (required)>'
    Tasks: TOP => db:migrate => environment
    (See full trace by running task with --trace)

Issue: Everytime I try to migrate I get this error. However, I do not have a devise.rb file installed so am not sure how to fix this..

Attempts to solve: tried this answer however that didn't let me populate the correct rake routes I needed (ie: new user sessions, create new user, etc..)

Tried redoing the order of commands (as shown below).. But that didn't work either.. I always get stuck at the "rake db:migrate" portion..

$ rails d devise User
$ rails generate devise:install (you may have to override previous files)
$ rails generate devise User
$ rake db:drop
$ rake db:create
$ rake db:migrate
$ rake routes 

Thank you in advance if you know the fix!!

It looks like you have devise generator previously run unsuccessfully. Backtrace gives a clue that error happens within config/routes.rb line 2. I guess there is a following line of code, setting up devise routes

devise_for :users

But your users model doesn't have devise modules setup. There should be something like

# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :timeoutable  and :omniauthable
devise :database_authenticatable, :rememberable, :trackable, :validatable

If this line is present it means that devise is improperly installed.

Also there is a chance that you have another class or module "User" within ActiveSupport::Dependencies autoloader paths and when devise_for :users line requires User class this class/module loaded first, whereas your real User module is not loaded. The "invalid" user module/class is not ActiveRecord descendant, so devise AR hook is not installed to it, so it doesn't have #devise method. So make sure you don't have any other classes/modules named User

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM