首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoMethodError在Devise::RegistrationsController#create中用于#<User:0x007fd83f5ccb68>的未定义方法`confirmation_sent_at=‘

NoMethodError在Devise::RegistrationsController#create中用于#<User:0x007fd83f5ccb68>的未定义方法`confirmation_sent_at=‘
EN

Stack Overflow用户
提问于 2015-09-01 23:47:24
回答 1查看 920关注 0票数 0

我对Rails很陌生。我正在使用设计添加认证和电子邮件确认注册后。当我在本地运行代码时,我会得到标题中的错误消息。我查看过类似的帖子,尝试运行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

代码语言:javascript
复制
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'

我很感激你的帮助!

添加了迁移文件

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2015-09-02 18:57:39

@魔杖制造者是正确的。代码应该反映confirmation_sent_at而不是confirmation_tokention_sent_at

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32342554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档