我正在创建一个这样的新迁移:
rails g migration add_confirmable_to_devise
它将在以下位置生成文件:db/migrate/YYYYMMDDxxx_add_confirmable_to_devise.rb
我添加这个:
class AddConfirmableToDevise < ActiveRecord::Migration
# Note: You can't use change, as User.update_all will fail in the down migration
def up
add_column :users, :confirmation_token, :string
add_column :users, :confirmed_at, :datetime
add_column :users, :confirmation_sent_at, :datetime
# add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
add_index :users, :confirmation_token, unique: true
# User.reset_column_information # Need for some types of updates, but not for update_all.
# To avoid a short time window between running the migration and updating all existing
# users as confirmed, do the following
User.update_all confirmed_at: DateTime.now
# All existing user accounts should be able to log in after this.
end
def down
remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
# remove_columns :users, :unconfirmed_email # Only if using reconfirmable
end
end
然后我做rake db:migrate
我明白了Process finished with exit code 0
但是当我尝试对其进行注册时,我得到:undefined local variable or method 'confirmed_at' for #User
我正在遵循以下说明here
是因为我有mongodb吗?在mongodb中它做的不同吗?
答案 0 :(得分:0)
否
使用Mongoid和MongoDB时,无需运行rake
db:migrate
。使用MongoDB的优点是不需要迁移或架构。
Mongoid不利用ActiveRecord迁移,因为MongoDB不需要在存储数据之前定义架构。
使用MongoDB时,您只需要在模型上配置字段。迁移(和模式)用于SQL数据库。