gpt4 book ai didi

ruby-on-rails - Devise 中的 NameError::SessionsController#create

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:34 25 4
gpt4 key购买 nike

我正在尝试使用 :lockable ,所以当我将它添加到 class User < ActiveRecord::Base 时并尝试登录或登录。我重定向到错误页面。这是我得到的

NameError in Devise::SessionsController#create
undefined local variable or method `locked_at' for #<User:0x000001025a56d8>

Rails.root: /Users/user/Ruby

Application Trace | Framework Trace | Full Trace
Request

Parameters:

{"utf8"=>"✓",
"authenticity_token"=>"dsfgsgfddsfgt5467657654n74=",
"user"=>{"email"=>"email@email.com",
"password"=>"[FILTERED]"},
"commit"=>"Sign in"}
Toggle session dump
Toggle env dump
Response

Headers:

None

有什么想法吗?当我删除 :lockable一切正常

最佳答案

设计需要 datetime :locked_at 字段。你一定错过了。

更新:

包括此迁移,因为您的 user 表中似乎没有合适的字段。

这样做

  1. rails g 迁移 add_devise_required_missing_fields

  2. 打开生成的迁移文件并粘贴这个

    change_table(:users) do |t|
    ## 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
    end
    add_index :users, :unlock_token, unique: true
  3. 最后,运行 rake db:migrate

关于ruby-on-rails - Devise 中的 NameError::SessionsController#create,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23849717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com