未定义的局部变量或#User的方法`confirmed_at’
我正在使用Rails 3.这里可能有重复。 但它没有解决我的问题,也没有解决任何其他问题。
我的迁移如下
class AddConfirmableToDevise true end end
我确实devise :confirmable
在User
模型中添加了devise :confirmable
。
我的rake db:migrate
没有输出。 我的注册页面给出了错误:
undefined local variable or method 'confirmed_at' for #User
有人有线索吗?
好。 我解决了 迁移已过时。 使用相同的代码生成新的迁移,但使用其他名称。
1.运行命令:
rails g migration add_confirmable_to_devise_v1
2.在迁移文件中:
class AddConfirmableToDeviseV1 < ActiveRecord::Migration def change change_table(:users) do |t| t.confirmable end add_index :users, :confirmation_token, :unique => true end end
3.Then
rake db:migrate
从最新设计开始,您只需要在设计用户迁移中删除以下行中的注释。(2013 ….._ devise_create_users.rb)
# Confirmable t.string :confirmation_token t.datetime :confirmed_at t.datetime :confirmation_sent_at t.string :unconfirmed_email # Only if using reconfirmable
要将@ DevDude的答案与已接受的答案联系起来 – 如果您已经有一个需要添加确认的现有Users
模型,则截至4月14日的Devise当前版本的完整迁移代码为:
class AddConfirmableToDeviseV1 < ActiveRecord::Migration def change 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 end add_index :users, :confirmation_token, :unique => true end end
请注意自己。 有人可能会觉得有用:我们需要的是以下两个命令:
rake db:migrate:reset rake db:reset
瞧! 有用!
我正在使用Mongoid并得到同样的错误。 我添加了这些字段,并在我的16个示例中获得了绿色标准。
field :confirmation_token, :type => String field :confirmed_at, :type => Time field :confirmation_sent_at, :type => Time field :unconfirmed_email, :type => String