I am using Rails 3. There is a possible duplicate here. But it did not solve my problem, neither did any other solution.
我正在使用Rails 3。这里可能有一个副本。但这并没有解决我的问题,也没有其他的解决办法。
My migration is as follows
我的迁移如下。
class AddConfirmableToDevise < ActiveRecord::Migration
def change
change_table(:users) do |t|
t.confirmable
end
add_index :users, :confirmation_token, :unique => true
end
end
I do have devise :confirmable
added in User
model.
我确实设计了:在用户模型中添加了可确认的。
My rake db:migrate
gives no output. and my sign up page gives the error:
我的rake db:migrate没有输出。我的注册页面出现了错误:
undefined local variable or method 'confirmed_at' for #User
Anybody has a clue?
有人有线索吗?
5 个解决方案
#1
25
Ok. I solved it. The migration is outdated. Generate new migration with same code but another name.
好的。我解决它。迁移是过时的。使用相同的代码生成新的迁移,但是使用另一个名称。
1.Run command:
1。运行命令:
rails g migration add_confirmable_to_devise_v1
2.In the migration file:
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
3.然后
rake db:migrate
#2
19
As of the latest devise, you just need to remove comments from the following lines on the devise users migration.. (2013....._devise_create_users.rb)
对于最新的设计,您只需要从设计用户迁移的下面几行删除注释。(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
#3
15
To tie in @DevDude's answer with the accepted answer - if you already have an existing Users
model to which you need to add confirmable, the full migration code for the version of Devise current as of 4/14 is:
要将@DevDude的答案与已接受的答案联系起来——如果您已经有一个需要添加可确认的现有用户模型,那么4/14版本的总体设计电流迁移代码是:
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
#4
14
Note for myself. Someone might find it helpful: What we need is 2 commands below:
注意自己。有人可能会觉得这很有帮助:我们需要以下两个命令:
rake db:migrate:reset
rake db:reset
Voila! It works!
瞧!它的工作原理!
#5
4
I'm using Mongoid and got this same error. I added these fields and got rspec to go green on my 16 examples.
我使用了Mongoid,得到了同样的错误。我添加了这些字段,并在我的16个例子中得到了rspec。
field :confirmation_token, :type => String
field :confirmed_at, :type => Time
field :confirmation_sent_at, :type => Time
field :unconfirmed_email, :type => String
#1
25
Ok. I solved it. The migration is outdated. Generate new migration with same code but another name.
好的。我解决它。迁移是过时的。使用相同的代码生成新的迁移,但是使用另一个名称。
1.Run command:
1。运行命令:
rails g migration add_confirmable_to_devise_v1
2.In the migration file:
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
3.然后
rake db:migrate
#2
19
As of the latest devise, you just need to remove comments from the following lines on the devise users migration.. (2013....._devise_create_users.rb)
对于最新的设计,您只需要从设计用户迁移的下面几行删除注释。(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
#3
15
To tie in @DevDude's answer with the accepted answer - if you already have an existing Users
model to which you need to add confirmable, the full migration code for the version of Devise current as of 4/14 is:
要将@DevDude的答案与已接受的答案联系起来——如果您已经有一个需要添加可确认的现有用户模型,那么4/14版本的总体设计电流迁移代码是:
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
#4
14
Note for myself. Someone might find it helpful: What we need is 2 commands below:
注意自己。有人可能会觉得这很有帮助:我们需要以下两个命令:
rake db:migrate:reset
rake db:reset
Voila! It works!
瞧!它的工作原理!
#5
4
I'm using Mongoid and got this same error. I added these fields and got rspec to go green on my 16 examples.
我使用了Mongoid,得到了同样的错误。我添加了这些字段,并在我的16个例子中得到了rspec。
field :confirmation_token, :type => String
field :confirmed_at, :type => Time
field :confirmation_sent_at, :type => Time
field :unconfirmed_email, :type => String