Reputation: 768
I upgraded my Rails version from 3.2 to 4.2.6 and devise version from 1.4.9 to 4.2.0. When I run my application with create update password, everything is fine. But when I upload my old production database dump into new one and try to reset password, I am facing this error:
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:insend_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:increate'
send_action' actionpack (4.2.6) lib/abstract_controller/base.rb:198:in
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:in__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
block 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:inprocess_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:inprocess' actionview (4.2.6) lib/action_view/rendering.rb:30:in
process' actionpack (4.2.6) lib/action_controller/metal.rb:196:indispatch' actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in
dispatch'
actionpack (4.2.6) lib/action_controller/metal.rb:237:inblock 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:inserve'
serve' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in
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
each' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:inserve'
call' 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' warden (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
call' rack (1.6.4) lib/rack/etag.rb:24:incall' rack (1.6.4) lib/rack/conditionalget.rb:38:in
call' rack (1.6.4) lib/rack/head.rb:13:incall' remotipart (1.2.1) lib/remotipart/middleware.rb:27:in
call' actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:incall'
call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in
actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:incontext' rack (1.6.4) lib/rack/session/abstract/id.rb:220:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:incall' 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:incall' 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:inrun_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:incall'
call'
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:in
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
block in tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:intagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in
tagged' railties (4.2.6) lib/rails/rack/logger.rb:20:incall' actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in
call' rack (1.6.4) lib/rack/methodoverride.rb:22:incall' 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:incall' rack (1.6.4) lib/rack/lock.rb:17:in
call' actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:incall' rack (1.6.4) lib/rack/sendfile.rb:113:in
call' railties (4.2.6) lib/rails/engine.rb:518:incall' railties (4.2.6) lib/rails/application.rb:165:in
call' rack (1.6.4) lib/rack/content_length.rb:15:incall' thin (1.5.1) lib/thin/connection.rb:81:in
block in pre_process' thin (1.5.1) lib/thin/connection.rb:79:incatch' thin (1.5.1) lib/thin/connection.rb:79:in
pre_process' thin (1.5.1) lib/thin/connection.rb:54:inprocess' thin (1.5.1) lib/thin/connection.rb:39:in
receive_data' eventmachine (1.0.9.1) lib/eventmachine.rb:193:inrun_machine' eventmachine (1.0.9.1) lib/eventmachine.rb:193:in
run' thin (1.5.1) lib/thin/backends/base.rb:63:instart' thin (1.5.1) lib/thin/server.rb:159:in
start' rack (1.6.4) lib/rack/handler/thin.rb:19:inrun' rack (1.6.4) lib/rack/server.rb:286:in
start' railties (4.2.6) lib/rails/commands/server.rb:80:instart' 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:intap'
server'
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:inrequire' 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
Old migration file:
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
Please help me how to solve the issue.
Upvotes: 3
Views: 792
Reputation: 685
@Edmund Lee point is correct, there is difference between 1.5 and latest version. As reset_password_sent_at is not found in your oldest version, it throws the error. For this you no need to change the devise side, just try to add:
ALTER TABLE users ADD reset_password_sent_at datetime;
to your script file and run (easy trick) and also there will be no problem when you add / edit users.
Upvotes: 1
Reputation: 2584
It's a new column that was added around version 1.5.
Check this link for the commint. https://github.com/plataformatec/devise/commit/7693173ecd7f9b4198fafabafa3bdced7fab16d3
Since you are from a old version, so your db doesn't have the new column available. You can run the migration and this particular problem should be fixed. But there might be more breaking changes since you are jumping three major versions.
Devise does a very good job in documentation. Before you update your version, check breaking changes. https://github.com/plataformatec/devise/releases
FYI:
I personally advise against jumping versions when it comes to big update (e.g. 1.x to 2.x), let along you are jumping from 1.x to 4.x.
In semantic versioning,
More about semantic versioning.
Upvotes: 3