Rails Devise Gem,(未定义的方法'to_datetime',用于nil:NilClass)当我想恢复密码时



我在使用 Devise Gem 时遇到问题,我使用的是默认的可恢复方法,链接正在发送。重置值(reset_password_sent_at)保存在数据库中,但是当我必须记下新密码并更新它时,会出现此错误

NoMethodError (undefined method `to_datetime' for nil:NilClass):
  activesupport (4.0.2) lib/active_support/core_ext/date_time/calculations.rb:161:in `<=>'
  activesupport (4.0.2) lib/active_support/core_ext/time/calculations.rb:286:in `compare_with_coercion'
  activesupport (4.0.2) lib/active_support/time_with_zone.rb:214:in `<=>'
  activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:97:in `=='
  activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:97:in `!='
  activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:97:in `_field_changed?'
  activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:66:in `write_attribute'
  activerecord (4.0.2) lib/active_record/attribute_methods/time_zone_conversion.rb:39:in `reset_password_sent_at='
  devise (3.5.6) lib/devise/models/recoverable.rb:94:in `clear_reset_password_token'
  devise (3.5.6) lib/devise/models/recoverable.rb:32:in `block (2 levels) in <module:Recoverable>'
  activesupport (4.0.2) lib/active_support/callbacks.rb:377:in `_run__1626105923374900797__update__callbacks'
  activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
  activerecord (4.0.2) lib/active_record/callbacks.rb:310:in `update_record'
  activerecord (4.0.2) lib/active_record/timestamp.rb:70:in `update_record'
  activerecord (4.0.2) lib/active_record/persistence.rb:477:in `create_or_update'
  activerecord (4.0.2) lib/active_record/callbacks.rb:302:in `block in create_or_update'
  activesupport (4.0.2) lib/active_support/callbacks.rb:393:in `_run__1626105923374900797__save__callbacks'
  activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
  activerecord (4.0.2) lib/active_record/callbacks.rb:302:in `create_or_update'
  activerecord (4.0.2) lib/active_record/persistence.rb:106:in `save'
  activerecord (4.0.2) lib/active_record/validations.rb:51:in `save'
  activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:32:in `save'
  activerecord (4.0.2) lib/active_record/transactions.rb:270:in `block (2 levels) in save'
  activerecord (4.0.2) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
  activerecord (4.0.2) lib/active_record/transactions.rb:209:in `transaction'
  activerecord (4.0.2) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
  activerecord (4.0.2) lib/active_record/transactions.rb:270:in `block in save'
  activerecord (4.0.2) lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
  activerecord (4.0.2) lib/active_record/transactions.rb:269:in `save'
  devise (3.5.6) lib/devise/models/recoverable.rb:48:in `reset_password'
  devise (3.5.6) lib/devise/models/recoverable.rb:141:in `reset_password_by_token'
  devise (3.5.6) app/controllers/devise/passwords_controller.rb:32:in `update'

调试它似乎是一个问题,当密码重置时,reset_password_sent_at为零(lib/devise/models/recoverable.rb:94:inclear_reset_password_token)

我尝试将本地时间更改为存储的 UTC,但问题不在于此。有什么建议吗?

我的解决方案是将我的 rails 从 4.0.2 升级到 4.2.7。当我运行捆绑包时,安装和更新 gemfile 依赖项现在正在工作。

将设备从 (3.5.6) 升级到 (4.2.0)

相关内容

  • 没有找到相关文章

最新更新