Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `password_digest=' for User while User Registration #1845

Closed
srkgupta opened this issue May 12, 2012 · 10 comments
Closed

undefined method `password_digest=' for User while User Registration #1845

srkgupta opened this issue May 12, 2012 · 10 comments

Comments

@srkgupta
Copy link

Hi,

I am getting this error "undefined method `password_digest=' for #<User" when I am trying to Sign up.

Steps I did:

  1. Deployed Rails 3.1.1 application on Heroku.
  2. Using Devise 2.0.4
  3. My user model file looks like this:
    class User < ActiveRecord::Base

Include default devise modules. Others available are:

:token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable

Setup accessible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me, :password_digest

end

@stevenh512
Copy link

Did you run the database migrations on Heroku (heroku run rake db:migrate)?

@srkgupta
Copy link
Author

I had loaded the database from schema (heroku rake db:load:schema). It creates the database and does not requires any migration.

@stevenh512
Copy link

Actually, I think I might see the problem, what does your migration look like?

It looks like you're trying to use password_digest (which ActiveModel's has_secure_password uses by default), when Devise uses encrypted_password instead.

BTW you probably shouldn't include the encrypted password in attr_accessible, with Devise (and with has_secure_password) the model handles that internally and it shouldn't be mass-assignable. 😁

@josevalim
Copy link
Contributor

@srkgupta Please provide the backtrace, it may help finding the error. If not, we would like to ask for a way to reproduce the issue.

@srkgupta
Copy link
Author

This is how migration file looks like.

class DeviseCreateUsers < ActiveRecord::Migration
def create
create_table(:users) do |t|
## Database authenticatable
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

  t.timestamps
end

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

end
end

And this is the backtrace:

.bundle/gems/ruby/1.9.1/gems/activemodel-3.1.1/lib/active_model/attribute_methods.rb:385:in method_missing' .bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/attribute_methods.rb:60:inmethod_missing'
.bundle/gems/ruby/1.9.1/gems/activemodel-3.1.1/lib/active_model/secure_password.rb:69:in password=' .bundle/gems/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/recoverable.rb:30:inreset_password!'
.bundle/gems/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/recoverable.rb:124:in reset_password_by_token' .bundle/gems/ruby/1.9.1/gems/devise-2.0.4/app/controllers/devise/passwords_controller.rb:28:inupdate'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/implicit_render.rb:4:in send_action' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/base.rb:167:inprocess_action'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/rendering.rb:10:in process_action' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/callbacks.rb:18:inblock in process_action'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:434:in _run__2188966773857631506__process_action__3617895183026444072__callbacks' .bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:386:in_run_process_action_callbacks'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in run_callbacks' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/callbacks.rb:17:inprocess_action'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/rescue.rb:17:in process_action' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/instrumentation.rb:30:inblock in process_action'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/notifications.rb:53:in block in instrument' .bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/notifications/instrumenter.rb:21:ininstrument'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/notifications.rb:53:in instrument' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/instrumentation.rb:29:inprocess_action'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:201:in process_action' .bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/railties/controller_runtime.rb:18:inprocess_action'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/base.rb:121:in process' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/rendering.rb:45:inprocess'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal.rb:193:in dispatch' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/rack_delegation.rb:14:indispatch'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal.rb:236:in block in action' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:65:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:65:in dispatch' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:29:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/routing/mapper.rb:41:in call' .bundle/gems/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:inblock in call'
.bundle/gems/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in block in recognize' .bundle/gems/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:inoptimized_each'
.bundle/gems/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in recognize' .bundle/gems/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:532:in call' .bundle/gems/ruby/1.9.1/gems/warden-1.1.1/lib/warden/manager.rb:35:inblock in call'
.bundle/gems/ruby/1.9.1/gems/warden-1.1.1/lib/warden/manager.rb:34:in catch' .bundle/gems/ruby/1.9.1/gems/warden-1.1.1/lib/warden/manager.rb:34:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/best_standards_support.rb:17:in call' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/etag.rb:23:incall'
.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/conditionalget.rb:35:in call' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/head.rb:14:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/params_parser.rb:21:in call' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/flash.rb:243:incall'
.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/session/abstract/id.rb:195:in context' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/session/abstract/id.rb:190:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/cookies.rb:331:in call' .bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/query_cache.rb:62:incall'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in call' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/callbacks.rb:29:inblock in call'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:392:in _run_call_callbacks' .bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:inrun_callbacks'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/callbacks.rb:28:in call' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/sendfile.rb:101:incall'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/remote_ip.rb:48:in call' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/show_exceptions.rb:47:incall'
.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/rack/logger.rb:13:in call' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/methodoverride.rb:24:incall'
.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/runtime.rb:17:in call' .bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/cache/strategy/local_cache.rb:72:incall'
.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/lock.rb:15:in call' .bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:53:incall'
.bundle/gems/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:132:in forward' .bundle/gems/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:139:inpass'
.bundle/gems/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:151:in invalidate' .bundle/gems/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:70:incall!'
.bundle/gems/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:50:in call' .bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:456:incall'
.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in method_missing' /home/heroku_rack/lib/static_assets.rb:9:incall'
/home/heroku_rack/lib/last_access.rb:15:in call' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/urlmap.rb:52:inblock in call'
.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/urlmap.rb:46:in each' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/urlmap.rb:46:incall'
/home/heroku_rack/lib/date_header.rb:14:in call' .bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:134:incall'
thin (1.2.6) lib/thin/connection.rb:76:in block in pre_process' thin (1.2.6) lib/thin/connection.rb:74:incatch'
thin (1.2.6) lib/thin/connection.rb:74:in pre_process' thin (1.2.6) lib/thin/connection.rb:57:inprocess'
thin (1.2.6) lib/thin/connection.rb:42:in receive_data' eventmachine (0.12.10) lib/eventmachine.rb:256:inrun_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in run' thin (1.2.6) lib/thin/backends/base.rb:57:instart'
thin (1.2.6) lib/thin/server.rb:156:in start' thin (1.2.6) lib/thin/controllers/controller.rb:80:instart'
thin (1.2.6) lib/thin/runner.rb:177:in run_command' thin (1.2.6) lib/thin/runner.rb:143:inrun!'
thin (1.2.6) bin/thin:6:in <top (required)>' /usr/ruby1.9.2/bin/thin:19:inload'
/usr/ruby1.9.2/bin/thin:19:in `

'

@josevalim
Copy link
Contributor

As @stevenh512 said, you are using ActiveModel's has_secure_password with Devise. You must not mix the two. Cheers.

@srkgupta
Copy link
Author

I do not have any reference to has_secure_password in my User Model. Can you please point me out where exactly is this being referenced.

I had even tried removing the attr_accessible for password_digest in my User Model file. But it still displays the same error.

@stevenh512
Copy link

Yeah, that's the problem, password_digest is for has_secure_password. Devise calls it encrypted_password instead.

Remove :password_digest from your attr_accessible and replace any other occurrences of password_digest in your model with encrypted_password. Also make sure you're not also using has_secure_password in your model, since Devise takes care of that for you. 😁

@josevalim
Copy link
Contributor

@srkgupta You can clearly see secure password in the backtrace .bundle/gems/ruby/1.9.1/gems/activemodel-3.1.1/lib/active_model/secure_password.rb:69. I don't have access to your code base, I cannot tell you where it is being included.

@srkgupta
Copy link
Author

Thank You Guys. I was actually having an another User model file user_old.rb which had used has_secure_password in it. I removed that file and it worked.

You guys Rock. Thanks once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants