简体   繁体   English

Rails:运行“ rails generate devise:install”时,用户不响应“ devise”方法

[英]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. 我已经在这个问题上工作了几个小时,而且似乎在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.. 但是,我没有安装devise.rb文件,因此不确定如何解决此问题。

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.. 尝试重做命令的顺序(如下所示)..但是那也不起作用..我总是卡在“ rake db:migrate”部分。

$ 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 Backtrace提供了一条线索,说明错误发生在config / routes.rb第2行中。我想下面的代码行设置了设计路线

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. 另外,还有可能在ActiveSupport :: Dependencies自动加载器路径中有另一个类或模块“ User”,并且当devise_for:users行要求User类首先加载此类/模块,而真正的User模块未加载时。 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. “无效”用户模块/类不是ActiveRecord的后代,因此未向其安装devise AR挂钩,因此它没有#devise方法。 So make sure you don't have any other classes/modules named User 因此,请确保您没有其他名为User的其他类/模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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