我对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
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'我很感激你的帮助!
添加了迁移文件
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发布于 2015-09-02 18:57:39
@魔杖制造者是正确的。代码应该反映confirmation_sent_at而不是confirmation_tokention_sent_at。
我必须采取的其他步骤是删除我的schema.rb文件,运行rake db:reset,然后运行rake db:migrate来创建更新的(并更正) schema.rb。
https://stackoverflow.com/questions/32342554
复制相似问题