`method_missing':未定义的方法`设计'用户错误

时间:2017-01-02 12:22:24

标签: ruby-on-rails

我在我的应用程序的Gem中下载了设计。当我在终端中bundle exec rails server -b 0.0.0.0时,我收到了一个错误:

.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `devise' for User (call 'User.connection' to establish a connection):Class (NoMethodError)

我读了上面错误的其他错误消息,它说

user.rb:4:in `<class:User>' and user.rb:1:in `<top (required)>'  

错了,但我不知道为什么这些句子是错的(因为它的部分是devise :database_authenticatable, :registerable

我该怎么做才能解决此错误?

我在user.rb档案中写道:

&#13;
&#13;
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
&#13;
&#13;
&#13;

在迁移文件中,

&#13;
&#13;
class DeviseCreateUsers < ActiveRecord::Migration
  def change
    create_table(:users) do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.string   :current_sign_in_ip
      t.string   :last_sign_in_ip

      ## Confirmable
      # t.string   :confirmation_token
      # t.datetime :confirmed_at
      # t.datetime :confirmation_sent_at
      # t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
      # t.string   :unlock_token # Only if unlock strategy is :email or :both
      # t.datetime :locked_at


      t.timestamps null: false
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    # add_index :users, :confirmation_token,   unique: true
    # add_index :users, :unlock_token,         unique: true
  end
end
&#13;
&#13;
&#13;

application_controller.rb档案中:

&#13;
&#13;
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  before_action :authenticate_user!
  protect_from_forgery with: :exception
end
&#13;
&#13;
&#13;

<{1>}文件中的

&#13;
&#13;
routes.rb
&#13;
&#13;
&#13;

0 个答案:

没有答案