用户的未定义方法“设计" [英] undefined method 'devise' for User

查看:14
本文介绍了用户的未定义方法“设计"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力掌握设计及其工作原理,但在第一个障碍中有点失败.我查看了几个地方,但似乎无法准确找到有此错误的人.

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.

因此,我创建了一个带有索引视图的简单 Home 控制器,并添加了 root 'home#index',并确保在 development.rb 文件中设置了默认 url 选项.然后我简单地输入:

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

这在具有以下内容的模型中创建了我的 user.rb 文件:

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

到目前为止非常简单,我有以下 Gemfile:

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'

当我运行 rake db:migrate 时,出现以下错误:

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)>'

我不知道为什么 User 模型找不到设计"方法,而据我所知它肯定存在.

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.

我在使用 rake 路由、rails 服务器和 rails 控制台时遇到了类似的错误.

I get similar errors with rake routes, rails server and rails console.

有关更多信息,我正在使用 ruby​​ 2.1.1 如果有帮助吗?

For further info I am using ruby 2.1.1 if that helps?

推荐答案

devise 添加到您的应用程序 Gemfile 并通过运行 bundle install 进行安装>.在此之后,您应该运行以下生成器命令:

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

这个生成器将安装一个初始化程序your_application/config/initializers/devise.rb,它包含所有设计的配置选项.

This generator will install an initializer your_application/config/initializers/devise.rb which consists of all the Devise's configuration options.

您错过了上述步骤,这就是为什么未设置设备配置并且您在模型类 User 中收到 undefined method 'devise' for User 错误的原因.

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.

这篇关于用户的未定义方法“设计"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆