Devise中的NoMethodError :: RegistrationsController #create undefined method`infirm_sent_at =&#39;对于#<user:0x007fd83f5ccb68>

时间:2015-09-01 23:47:24

标签: ruby-on-rails ruby devise

我是Rails的新手。我在注册时使用Devise添加身份验证和电子邮件确认。当我在本地运行代码时,我在标题中收到错误消息。我查看了类似帖子并尝试运行rake db:reset并重新启动服务器。

我已将:confirmable添加到models/user.rb

class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable end

错误消息突出显示此代码块,并特别调出以match ?开头的代码行433行

else match = match_attribute_method?(method.to_s) match ? attribute_missing(match, *args, &block) : super end end

Completed 500 Internal Server Error in 327ms (ActiveRecord: 0.5ms)

NoMethodError (undefined method `confirmation_sent_at=' for #   <User:0x007fd21e2ebce0>):
 activemodel (4.2.3) lib/active_model/attribute_methods.rb:433:in `method_missing'
 devise (3.5.2) lib/devise/models/confirmable.rb:240:in `generate_confirmation_token'
 activesupport (4.2.3) lib/active_support/callbacks.rb:430:in `block in make_lambda'
 activesupport (4.2.3) lib/active_support/callbacks.rb:143:in `call'

我感谢任何帮助!

添加了迁移文件

class DeviseCreateUsers < ActiveRecord::Migration
  def change
    create_table(:users) do |t|
      ## Database authenticatable
      t.string :name
      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_tokention_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

1 个答案:

答案 0 :(得分:0)

@Wand Maker是正确的。代码应反映confirmation_sent_at而不是confirmation_tokention_sent_at

我必须采取的额外步骤是删除我的schema.rb文件,运行rake db:reset然后rake db:migrate以创建更新的(并且正确的)schema.rb