3
votes

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:inset_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'
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'
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:incall' activesupport (4.2.6) lib/active_support/callbacks.rb:92:in __run_callbacks__'
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:inprocess_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:inblock in process_action' activesupport (4.2.6) lib/active_support/notifications.rb:164:in block in instrument'
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:inprocess_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:inprocess' actionpack (4.2.6) lib/action_controller/metal.rb:196:in dispatch' actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:indispatch'
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:indispatch' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in serve'
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:ineach' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in serve'
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'
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:incall' rack (1.6.4) lib/rack/etag.rb:24:in call' rack (1.6.4) lib/rack/conditionalget.rb:38:incall' rack (1.6.4) lib/rack/head.rb:13:in call' remotipart (1.2.1) lib/remotipart/middleware.rb:27:incall' actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in call'
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:incall'
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:inblock 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:incall' actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in call'
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'
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:inblock 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:intagged' railties (4.2.6) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:incall' rack (1.6.4) lib/rack/methodoverride.rb:22:in call' rack (1.6.4) lib/rack/runtime.rb:18:incall' 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:incall' railties (4.2.6) lib/rails/engine.rb:518:in call' railties (4.2.6) lib/rails/application.rb:165:incall' rack (1.6.4) lib/rack/content_length.rb:15:in call' thin (1.5.1) lib/thin/connection.rb:81:inblock in pre_process' thin (1.5.1) lib/thin/connection.rb:79:in catch' thin (1.5.1) lib/thin/connection.rb:79:inpre_process' thin (1.5.1) lib/thin/connection.rb:54:in process' thin (1.5.1) lib/thin/connection.rb:39:inreceive_data' eventmachine (1.0.9.1) lib/eventmachine.rb:193:in run_machine' eventmachine (1.0.9.1) lib/eventmachine.rb:193:inrun' thin (1.5.1) lib/thin/backends/base.rb:63:in start' thin (1.5.1) lib/thin/server.rb:159:instart' rack (1.6.4) lib/rack/handler/thin.rb:19:in run' rack (1.6.4) lib/rack/server.rb:286:instart' railties (4.2.6) lib/rails/commands/server.rb:80:in start' railties (4.2.6) lib/rails/commands/commands_tasks.rb:80:inblock in server'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in tap'
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

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.

2
did you run migration after updating the version? it looks like a new column name to me. So if your db was at a older version you might not have the column available.Edmund Lee

2 Answers

1
votes

@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.

3
votes

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,

  • The last digit is usually just patches. If you are upgrading from the last digit (e.g. 1.4.2 to 1.4.5).
  • The second digit is minor changes, which might introduce some deprecations and some breaking changes depending on how they manage their versions
  • The first digit is always a major update and involves bigger change, and you should be very careful with.

More about semantic versioning.

http://semver.org/