Devise: NoMethodError: undefined method `will_save_change_to_email?'

Created on 10 May 2017  路  15Comments  路  Source: heartcombo/devise

undefined method `will_save_change_to_email?' for #

Devise 4.2.1 from master branch
Mongo 2.4.1
Ruby 2.4.1-p111
Rails 5.1.0

Most helpful comment

Ok from master

All 15 comments

@negrienko can you please again with 3e1c9e343ce537e3c9aabd74592e375152482045 or newer? If it works we can cut a new release.

Ok from master

@negrienko thanks for double checking this :). Version 4.3.0 is out.

Same error occurred.

Devise 4.3.0
Mongoid 6.1.1
Ruby 2.4.1-p111
Rails 5.1.1

Does anyone know about this solution?

@hisa0507 can you please provide a sample app that reproduces the issue?

@lucasmazza OK. I'll show you Full trace here.
Please let me know if you want any other information, thanks.

=================
undefined method `will_save_change_to_email?' for #

vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:413:in block in make_lambda' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:177:inblock (2 levels) in halting_and_conditional'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:177:in each' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:177:inall?'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:177:in block in halting_and_conditional' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:507:inblock in invoke_before'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:507:in each' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:507:ininvoke_before'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:130:in run_callbacks' vendor/bundle/ruby/2.4.0/gems/mongoid-6.1.1/lib/mongoid/interceptable.rb:132:inrun_callbacks'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:825:in _run_validate_callbacks' vendor/bundle/ruby/2.4.0/gems/activemodel-5.1.1/lib/active_model/validations.rb:405:inrun_validations!'
vendor/bundle/ruby/2.4.0/gems/activemodel-5.1.1/lib/active_model/validations/callbacks.rb:110:in block in run_validations!' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:131:inrun_callbacks'
vendor/bundle/ruby/2.4.0/gems/mongoid-6.1.1/lib/mongoid/interceptable.rb:132:in run_callbacks' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:825:in_run_validation_callbacks'
vendor/bundle/ruby/2.4.0/gems/activemodel-5.1.1/lib/active_model/validations/callbacks.rb:110:in run_validations!' vendor/bundle/ruby/2.4.0/gems/activemodel-5.1.1/lib/active_model/validations.rb:335:invalid?'
vendor/bundle/ruby/2.4.0/gems/mongoid-6.1.1/lib/mongoid/validatable.rb:97:in valid?' vendor/bundle/ruby/2.4.0/gems/activemodel-5.1.1/lib/active_model/validations.rb:372:ininvalid?'
vendor/bundle/ruby/2.4.0/gems/mongoid-6.1.1/lib/mongoid/persistable/creatable.rb:115:in prepare_insert' vendor/bundle/ruby/2.4.0/gems/mongoid-6.1.1/lib/mongoid/persistable/creatable.rb:23:ininsert'
vendor/bundle/ruby/2.4.0/gems/mongoid-6.1.1/lib/mongoid/persistable/savable.rb:23:in save' app/controllers/reviewers_controller.rb:261:inregistrations'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal/basic_implicit_render.rb:4:in send_action' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/abstract_controller/base.rb:186:inprocess_action'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal/rendering.rb:30:in process_action' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/abstract_controller/callbacks.rb:20:inblock in process_action'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:131:in run_callbacks' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/abstract_controller/callbacks.rb:19:inprocess_action'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal/rescue.rb:20:in process_action' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal/instrumentation.rb:32:inblock in process_action'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/notifications.rb:166:in block in instrument' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/notifications/instrumenter.rb:21:ininstrument'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/notifications.rb:166:in instrument' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal/instrumentation.rb:30:inprocess_action'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal/params_wrapper.rb:252:in process_action' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/abstract_controller/base.rb:124:inprocess'
vendor/bundle/ruby/2.4.0/gems/actionview-5.1.1/lib/action_view/rendering.rb:30:in process' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal.rb:189:indispatch'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_controller/metal.rb:253:in dispatch' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/routing/route_set.rb:49:indispatch'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/routing/route_set.rb:31:in serve' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/journey/router.rb:46:inblock in serve'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/journey/router.rb:33:in each' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/journey/router.rb:33:inserve'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/routing/route_set.rb:832:in call' vendor/bundle/ruby/2.4.0/gems/warden-1.2.7/lib/warden/manager.rb:36:inblock in call'
vendor/bundle/ruby/2.4.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in catch' vendor/bundle/ruby/2.4.0/gems/warden-1.2.7/lib/warden/manager.rb:35:incall'
vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/etag.rb:25:in call' vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/conditional_get.rb:38:incall'
vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/head.rb:12:in call' vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:232:incontext'
vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in call' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/cookies.rb:613:incall'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/callbacks.rb:26:in block in call' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/callbacks.rb:97:inrun_callbacks'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/callbacks.rb:24:in call' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/executor.rb:12:incall'
vendor/bundle/ruby/2.4.0/gems/airbrake-5.8.1/lib/airbrake/rack/middleware.rb:52:in call' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:59:incall'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/show_exceptions.rb:31:in call' vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/rack/logger.rb:36:incall_app'
vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/rack/logger.rb:24:in block in call' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/tagged_logging.rb:69:inblock in tagged'
vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/tagged_logging.rb:26:in tagged' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/tagged_logging.rb:69:intagged'
vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/rack/logger.rb:24:in call' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/remote_ip.rb:79:incall'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/request_id.rb:25:in call' vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/method_override.rb:22:incall'
vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/runtime.rb:22:in call' vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/cache/strategy/local_cache_middleware.rb:27:incall'
vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/executor.rb:12:in call' vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/static.rb:125:incall'
vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in call' vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/engine.rb:522:incall'
vendor/bundle/ruby/2.4.0/gems/stackprof-0.2.10/lib/stackprof/middleware.rb:21:in call' vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:606:inprocess_client'
vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:702:in worker_loop' vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:549:inspawn_missing_workers'
vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:142:in start' vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/bin/unicorn_rails:209:in vendor/bundle/ruby/2.4.0/bin/unicorn_rails:22:in load' vendor/bundle/ruby/2.4.0/bin/unicorn_rails:22:in bundler (1.14.6) lib/bundler/cli/exec.rb:74:in load' bundler (1.14.6) lib/bundler/cli/exec.rb:74:inkernel_load'
bundler (1.14.6) lib/bundler/cli/exec.rb:27:in run' bundler (1.14.6) lib/bundler/cli.rb:335:inexec'
bundler (1.14.6) lib/bundler/vendor/thor/lib/thor/command.rb:27:in run' bundler (1.14.6) lib/bundler/vendor/thor/lib/thor/invocation.rb:126:ininvoke_command'
bundler (1.14.6) lib/bundler/vendor/thor/lib/thor.rb:359:in dispatch' bundler (1.14.6) lib/bundler/cli.rb:20:indispatch'
bundler (1.14.6) lib/bundler/vendor/thor/lib/thor/base.rb:440:in start' bundler (1.14.6) lib/bundler/cli.rb:11:instart'
bundler (1.14.6) exe/bundle:32:in block in <top (required)>' bundler (1.14.6) lib/bundler/friendly_errors.rb:121:inwith_friendly_errors'
bundler (1.14.6) exe/bundle:24:in <top (required)>' /Users/hanlab/.rbenv/versions/2.4.1/bin/bundle:22:inload'
/Users/hanlab/.rbenv/versions/2.4.1/bin/bundle:22:in `

'

@hisa0507 the stack trace won't cut for this one - we need a sample Rails app hosted on a public GitHub repo that anyone can clone locally, replicate the error and debug through the code.

@lucasmazza Oh, I created new rails sample repo, but it cannot replicate. This problem occurred just in my app.. Hmm..

Is it still?

I am getting the same error too with Rails 5.1+. Works fine with Rails version 5.0

Problem happens with Rails 5.1 in https://github.com/plataformatec/devise/blob/master/lib/devise/models/validatable.rb.

if Devise.activerecord51?
聽聽聽聽聽聽聽聽validates_uniqueness_of :email, allow_blank: true, if: :will_save_change_to_email?
聽聽聽聽聽聽聽聽validates_format_of :email, with: email_regexp, allow_blank: true, if: :will_save_change_to_email?
else
聽聽聽聽聽聽聽聽validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
聽聽聽聽聽聽聽聽validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
end

I am having the same issue

Devise 4.2.1
Mongo 2.4.1
Ruby 2.4.1
Rails 5.1.1

Anyone got it working?

I am having the same issue as well after trying to upgrade our app from Rails 5.0.5 to 5.1.3. To reproduce:

Clone this repo: https://github.com/18F/identity-idp/tree/mb-update-redis-session-store
Checkout the mb-update-redis-session-store branch
run make setup

One thing that comes to mind is that we don't have an email field in the Users table because we encrypt the email. Instead, we have defined a getter method to access the email here:
https://github.com/18F/identity-idp/blob/mb-update-redis-session-store/app/models/concerns/encryptable_attribute.rb#L13-L19

I just remembered we had to override email_changed? and email_was in our app because it's not a database field, so to be able to upgrade to Rails 5.1, all I had to do was rename email_changed? to will_save_change_to_email? and email_was to email_in_database.

Unfortunately, these new Rails 5.1 methods are not yet documented here: http://api.rubyonrails.org/classes/ActiveModel/Dirty.html, but you can read about them here:
https://github.com/rails/rails/pull/25337#issuecomment-225166796

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pedroknoll picture Pedroknoll  路  3Comments

Gorchel picture Gorchel  路  3Comments

emn178 picture emn178  路  4Comments

JanBussieck picture JanBussieck  路  3Comments

spaquet picture spaquet  路  3Comments