gpt4 book ai didi

ruby-on-rails - 在 Rails 4.2.6 中升级设备时未定义的方法`reset_password_sent_at

转载 作者:行者123 更新时间:2023-12-04 02:09:19 27 4
gpt4 key购买 nike

我将我的 Rails 版本从 3.2 升级到 4.2.6,并将设计版本从 1.4.9 升级到 4.2.0。当我使用创建更新密码运行我的应用程序时,一切都很好。但是当我将旧的生产数据库转储上传到新数据库并尝试重置密码时,我遇到了这个错误:

NoMethodError (undefined method `reset_password_sent_at=' for

Did you mean? reset_password_token_was): activemodel (4.2.6) lib/active_model/attribute_methods.rb:433:in

method_missing' devise (4.2.0)
lib/devise/models/recoverable.rb:87:in
set_reset_password_token'
devise (4.2.0) lib/devise/models/recoverable.rb:45:in send_reset_password_instructions' devise (4.2.0)
lib/devise/models/recoverable.rb:119:in
send_reset_password_instructions' devise (4.2.0) app/controllers/devise/passwords_controller.rb:13:in create'<br/>
actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:in
send_action' actionpack (4.2.6) lib/abstract_controller/base.rb:198:in process_action' actionpack
(4.2.6) lib/action_controller/metal/rendering.rb:10:in
process_action' actionpack (4.2.6) lib/abstract_controller/callbacks.rb:20:in block in process_action'<br/>
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in
call'
activesupport (4.2.6) lib/active_support/callbacks.rb:555:in block (2
levels) in compile' activesupport (4.2.6)
lib/active_support/callbacks.rb:505:in
call' activesupport (4.2.6) lib/active_support/callbacks.rb:92:in __run_callbacks__'<br/>
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in
_run_process_action_callbacks' activesupport (4.2.6) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack
(4.2.6) lib/abstract_controller/callbacks.rb:19:in
process_action'
actionpack (4.2.6) lib/action_controller/metal/rescue.rb:29:in process_action' actionpack (4.2.6)
lib/action_controller/metal/instrumentation.rb:32:in
block in process_action' activesupport (4.2.6) lib/active_support/notifications.rb:164:in block in instrument'<br/>
activesupport (4.2.6)
lib/active_support/notifications/instrumenter.rb:20:in
instrument'
activesupport (4.2.6) lib/active_support/notifications.rb:164:in instrument' actionpack (4.2.6)
lib/action_controller/metal/instrumentation.rb:30:in
process_action' actionpack (4.2.6) lib/action_controller/metal/params_wrapper.rb:250:in process_action'
activerecord (4.2.6)
lib/active_record/railties/controller_runtime.rb:18:in
process_action' actionpack (4.2.6) lib/abstract_controller/base.rb:137:in process' actionview (4.2.6)
lib/action_view/rendering.rb:30:in
process' actionpack (4.2.6) lib/action_controller/metal.rb:196:in dispatch' actionpack (4.2.6)
lib/action_controller/metal/rack_delegation.rb:13:in
dispatch'
actionpack (4.2.6) lib/action_controller/metal.rb:237:in block in
action' actionpack (4.2.6)
lib/action_dispatch/routing/route_set.rb:74:in
dispatch' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in serve'<br/>
actionpack (4.2.6) lib/action_dispatch/routing/mapper.rb:49:in
serve' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in block
in serve' actionpack (4.2.6)
lib/action_dispatch/journey/router.rb:30:in
each' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in serve'<br/>
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in
call' warden (1.2.6) lib/warden/manager.rb:35:in block in call'<br/>
warden (1.2.6) lib/warden/manager.rb:34:in
catch' warden (1.2.6) lib/warden/manager.rb:34:in call' client_side_validations (4.2.5)
lib/client_side_validations/middleware.rb:15:in
call' rack (1.6.4) lib/rack/etag.rb:24:in call' rack (1.6.4)
lib/rack/conditionalget.rb:38:in
call' rack (1.6.4) lib/rack/head.rb:13:in call' remotipart (1.2.1)
lib/remotipart/middleware.rb:27:in
call' actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in call'<br/>
actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in
call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in call' activerecord (4.2.6) lib/active_record/query_cache.rb:36:in
call' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in call' actionpack (4.2.6)
lib/action_dispatch/middleware/callbacks.rb:29:in
block in call'
activesupport (4.2.6) lib/active_support/callbacks.rb:88:in __run_callbacks__' activesupport (4.2.6)
lib/active_support/callbacks.rb:778:in
_run_call_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.6)
lib/action_dispatch/middleware/callbacks.rb:27:in
call' actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in call'<br/>
actionpack (4.2.6)
lib/action_dispatch/middleware/debug_exceptions.rb:17:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in call'<br/>
railties (4.2.6) lib/rails/rack/logger.rb:38:in
call_app' railties (4.2.6) lib/rails/rack/logger.rb:20:in block in call' activesupport
(4.2.6) lib/active_support/tagged_logging.rb:68:in
block in tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.2.6)
lib/active_support/tagged_logging.rb:68:in
tagged' railties (4.2.6) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.6)
lib/action_dispatch/middleware/request_id.rb:21:in
call' rack (1.6.4) lib/rack/methodoverride.rb:22:in call' rack (1.6.4)
lib/rack/runtime.rb:18:in
call' activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' rack (1.6.4) lib/rack/lock.rb:17:incall' actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in call' rack
(1.6.4) lib/rack/sendfile.rb:113:in
call' railties (4.2.6) lib/rails/engine.rb:518:in call' railties (4.2.6)
lib/rails/application.rb:165:in
call' rack (1.6.4) lib/rack/content_length.rb:15:in call' thin (1.5.1)
lib/thin/connection.rb:81:in
block in pre_process' thin (1.5.1) lib/thin/connection.rb:79:in catch' thin (1.5.1)
lib/thin/connection.rb:79:in
pre_process' thin (1.5.1) lib/thin/connection.rb:54:in process' thin (1.5.1)
lib/thin/connection.rb:39:in
receive_data' eventmachine (1.0.9.1) lib/eventmachine.rb:193:in run_machine' eventmachine (1.0.9.1)
lib/eventmachine.rb:193:in
run' thin (1.5.1) lib/thin/backends/base.rb:63:in start' thin (1.5.1)
lib/thin/server.rb:159:in
start' rack (1.6.4) lib/rack/handler/thin.rb:19:in run' rack (1.6.4)
lib/rack/server.rb:286:in
start' railties (4.2.6) lib/rails/commands/server.rb:80:in start' railties (4.2.6)
lib/rails/commands/commands_tasks.rb:80:in
block in server'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in tap'<br/>
railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in
server'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:39:in run_command!' railties (4.2.6) lib/rails/commands.rb:17:in' bin/rails:4:in require' bin/rails:4:in'

db/migrate/xxxxxxxx_devise_create_users.rb:

class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
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
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip

## Encryptable
# t.string :password_salt

## Confirmable
t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable

## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at

# Token authenticatable
# t.string :authentication_token

## Invitable
# t.string :invitation_token

t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :reset_password_token, :unique => true
end

def self.down
drop_table :users
end
end

旧迁移文件:

class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both

t.timestamps
end

add_index :users, :email, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :unlock_token, :unique => true
end

def self.down
drop_table :users
end
end

请帮我解决这个问题。

最佳答案

这是一个新的专栏,是在 1.5 版本前后添加的。

检查此链接以获取提交信息。 https://github.com/plataformatec/devise/commit/7693173ecd7f9b4198fafabafa3bdced7fab16d3

由于您来自旧版本,因此您的数据库没有可用的新列。您可以运行迁移,这个特定问题应该得到解决。但由于您要跳过三个主要版本,因此可能会有更多重大更改。

Devise 在文档方面做得非常好。在更新版本之前,请检查重大更改。 https://github.com/plataformatec/devise/releases

仅供引用:

我个人建议不要在大更新时跳版本(例如 1.x 到 2.x),让你从 1.x 跳到 4.x。

在语义版本控制中,

  • 最后一位数字通常只是补丁。如果您从最后一位数字(例如 1.4.2 到 1.4.5)。
  • 第二个数字是微小的变化,可能会引入一些弃用和一些重大变化取决于他们如何管理他们的版本
  • 第一个数字总是重大更新,涉及更大的变化,你应该非常小心。

关于语义版本控制的更多信息。

http://semver.org/

关于ruby-on-rails - 在 Rails 4.2.6 中升级设备时未定义的方法`reset_password_sent_at,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40224358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com