我将Rails版本从3.2升级到4.2.6,并将版本从1.4.9升级到4.2.0。当我使用创建更新密码运行我的应用程序时,一切都很好。但是当我将旧的生产数据库转储上传到新的转储并尝试重置密码时,我遇到了这个错误:
NoMethodError(未定义的方法`reset_password_sent_at =' for
你的意思是? 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'
设计(4.2.0)lib / devise / models / recoverable.rb:45:insend_reset_password_instructions' devise (4.2.0) lib/devise/models/recoverable.rb:119:in
send_reset_password_instructions'设计(4.2.0) app / controllers / devise / passwords_controller.rb:13:increate'
send_action' actionpack(4.2.6) lib / abstract_controller / base.rb:198:在
actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:inprocess_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:inblock in process_action'
call'
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in
activesupport(4.2.6)lib / active_support / callbacks.rb:555:inblock (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:在__run_callbacks__'
_ run_process_action_callbacks' activesupport(4.2.6) lib / active_support / callbacks.rb:81:in
activesupport (4.2.6) lib/active_support/callbacks.rb:778:inrun_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:inprocess_action' actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in
阻止 process_action' activesupport(4.2.6) lib / active_support / notifications.rb:164:inblock in instrument'
instrument'
activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in
activesupport(4.2.6)lib / active_support / notifications.rb:164:ininstrument' 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:在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:在process' actionview (4.2.6) lib/action_view/rendering.rb:30:in
进程' actionpack(4.2.6) lib / action_controller / metal.rb:196:在dispatch' actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in
发送'
actionpack(4.2.6)lib / action_controller / metal.rb:237:在block in action' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in
发送' ActionPack的 (4.2.6)lib / action_dispatch / routing / route_set.rb:43:在serve'
发送' actionpack(4.2.6)lib / action_dispatch / journey / router.rb:43:
actionpack (4.2.6) lib/action_dispatch/routing/mapper.rb:49:inblock in serve' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in
每个' ActionPack的 (4.2.6)lib / action_dispatch / journey / router.rb:30:在serve'
电话' warden(1.2.6)lib / warden / manager.rb:35:in
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:inblock in call'
catch'监狱长(1.2.6) lib / warden / manager.rb:34:in
warden (1.2.6) lib/warden/manager.rb:34:incall' client_side_validations (4.2.5) lib/client_side_validations/middleware.rb:15:in
来电'机架(1.6.4) lib / rack / etag.rb:24:incall' rack (1.6.4) lib/rack/conditionalget.rb:38:in
来电'机架(1.6.4) lib / rack / head.rb:13:incall' remotipart (1.2.1) lib/remotipart/middleware.rb:27:in
来电' actionpack(4.2.6) lib / action_dispatch / middleware / params_parser.rb:27:incall'
来电' rack(1.6.4)lib / rack / session / abstract / id.rb:225:
actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:incontext' rack (1.6.4) lib/rack/session/abstract/id.rb:220:in
来电'
actionpack(4.2.6)lib / action_dispatch / middleware / cookies.rb:560:incall' activerecord (4.2.6) lib/active_record/query_cache.rb:36:in
呼叫' activerecord(4.2.6) LIB / active_record / connection_adapters /抽象/ connection_pool.rb:653:在call' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in
阻止通话'
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:inrun_callbacks' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in
呼叫' ActionPack的 (4.2.6)lib / action_dispatch / middleware / remote_ip.rb:78:incall'
来电'
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in
actionpack(4.2.6) lib / action_dispatch / middleware / show_exceptions.rb:30:incall'
call_app' railties (4.2.6)lib / rails / rack / logger.rb:20:在
railties (4.2.6) lib/rails/rack/logger.rb:38:inblock in call' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in
块中标记为'
activesupport(4.2.6)lib / active_support / tagged_logging.rb:26:intagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in
标记'铁路(4.2.6) lib / rails / rack / logger.rb:20:incall' actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in
来电'架 (1.6.4)lib / rack / methodoverride.rb:22:在call' rack (1.6.4) lib/rack/runtime.rb:18:in
电话' activesupport(4.2.6) LIB / active_support /缓存/策略/ local_cache_middleware.rb:28:在call' rack (1.6.4) lib/rack/lock.rb:17:in
呼叫' ActionPack的 (4.2.6)lib / action_dispatch / middleware / static.rb:120:在call' rack (1.6.4) lib/rack/sendfile.rb:113:in
电话'铁路(4.2.6) lib / rails / engine.rb:518:在call' railties (4.2.6) lib/rails/application.rb:165:in
来电'机架(1.6.4) lib / rack / content_length.rb:15:在pre_process'中的call' thin (1.5.1) lib/thin/connection.rb:81:in
块中薄(1.5.1) lib / thin / connection.rb:79:在catch' thin (1.5.1) lib/thin/connection.rb:79:in
pre_process'薄(1.5.1) lib / thin / connection.rb:54:inprocess' thin (1.5.1) lib/thin/connection.rb:39:in
receive_data'事件机器(1.0.9.1) lib / eventmachine.rb:193:在run_machine' eventmachine (1.0.9.1) lib/eventmachine.rb:193:in
运行'薄(1.5.1) lib / thin / backends / base.rb:63:instart' thin (1.5.1) lib/thin/server.rb:159:in
start'机架(1.6.4) lib / rack / handler / thin.rb:19:inrun' rack (1.6.4) lib/rack/server.rb:286:in
start'铁路(4.2.6) lib / rails / commands / server.rb:80:在服务器的start' railties (4.2.6) lib/rails/commands/commands_tasks.rb:80:in
块中'
railties(4.2.6)lib / rails / commands / commands_tasks.rb:75:intap'
服务器'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in
railties(4.2.6)lib / rails / commands / commands_tasks.rb:39:inrun_command!' railties (4.2.6) lib/rails/commands.rb:17:in
' bin / rails:4:require' bin/rails:4:in
'
分贝/迁移/ 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
请帮我解决问题。
答案 0 :(得分:2)
这是在1.5版本附近添加的新专栏。
检查此链接以获取commint。 https://github.com/plataformatec/simple_form/wiki/Nested-Models
由于您来自旧版本,因此您的数据库没有新列可用。您可以运行迁移,应修复此特定问题。但是,由于你跳过三个主要版本,可能会有更多的重大变化。
Devise在文档方面做得很好。在更新版本之前,请检查重大更改。 https://github.com/plataformatec/devise/commit/7693173ecd7f9b4198fafabafa3bdced7fab16d3
<强>供参考:强>
我个人建议不要在大更新时跳转版本(例如1.x到2.x),让你从1.x跳到4.x.
在语义版本控制中,
有关语义版本控制的更多信息。
答案 1 :(得分:1)
ALTER TABLE users ADD reset_password_sent_at datetime;
到您的脚本文件并运行(简单技巧),并且在添加/编辑用户时也没有问题。