用户未定义的方法'devise' [英] undefined method 'devise' for User
问题描述
所以我创建了一个简单的家庭控制器与索引视图,并添加根目录#index',并确保在development.rb文件中设置默认的url选项。然后我简单地键入:
rails generate devise用户
这个在以下模型中创建了我的user.rb文件:
class用户< ActiveRecord :: Base
#包含默认设计模块。其他可用的是:
#:confirmable,:lockedable,:timeoutable和:omniauthable
devise:database_authenticatable,:可注册,
:可恢复,可记忆,可追溯,可验证
结束
到目前为止,我有以下Gemfile:
源'https://rubygems.org'
gem'rails','4.0.5'
gem'sqlite3'
宝石'sass-rails','〜> 4.0.2'
gem'devise'
gem'uglifier','> = 1.3.0'
gem'coffee-rails','〜> 4.0.0'
gem'jquery-rails'
gem'turbolinks'
gem'jbuilder','〜> 1.2'
group:doc do
gem'sdoc',require:false
end
gem'bcrypt'
当我运行rake db:migrate时,我收到以下错误:
耙子中止了!
NoMethodError:为用户设定devise的未定义方法(调用User.connection建立连接):Class
/home/jonlee/.rvm/gems/ruby-2.1.1@railstutorial_rails_4_0/gems /activerecord-4.0.5/lib/active_record/dynamic_matchers.rb:22:in`method_missing'
/home/jonlee/Projects/rails/userauth/app/models/user.rb:4:in`< class:User>'
/home/jonlee/Projects/rails/userauth/app/models/user.rb:1:in`< top(required)>'
我很遗憾,为什么用户模型找不到设计方法,只要我能看到它绝对在那里。 / p>
我与耙子路线,rails服务器和rails控制台出现类似的错误。
有关更多信息,我使用的是ruby 2.1.1如果这有帮助?
将 devise
添加到您的应用程序 Gemfile
并通过运行 bundle install
进行安装。之后,您应该运行以下生成器命令:
rails generate devise:install
此生成器将安装一个初始化程序 your_application / config / initializers / devise.rb
所有Devise的配置选项。
您错过了上述步骤,这就是为什么设置配置未设置,您收到未定义的方法'devise'为用户
您的模型类中的错误用户
。
I have been looking to get to grips with devise and its workings and have kind of fallen at the first hurdle. I have looked in a few places but cannot seem to find someone with this error exactly.
So I have created a simple Home controller with an index view and added root 'home#index' and also ensured the default url options are setup in the development.rb file. I then simply typed:
rails generate devise User
This created my user.rb file in models with the following:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
Pretty straightforward so far, I have the following Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.5'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.2'
gem 'devise'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
gem 'bcrypt'
And when I run either rake db:migrate I get the following error:
rake aborted!
NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
/home/jonlee/.rvm/gems/ruby-2.1.1@railstutorial_rails_4_0/gems/activerecord-4.0.5/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/home/jonlee/Projects/rails/userauth/app/models/user.rb:4:in `<class:User>'
/home/jonlee/Projects/rails/userauth/app/models/user.rb:1:in `<top (required)>'
Im at a loss as to why the User model cannot find the 'devise' method when as far as I can see it is definitely there.
I get similar errors with rake routes, rails server and rails console.
For further info I am using ruby 2.1.1 if that helps?
Add devise
to your application Gemfile
and install it by running bundle install
. After this, you should run the following generator command:
rails generate devise:install
This generator will install an initializer your_application/config/initializers/devise.rb
which consists of all the Devise's configuration options.
You missed the above mentioned step which is why the devise configurations are not set and you receive undefined method 'devise' for User
error in your model class User
.
这篇关于用户未定义的方法'devise'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!