NoMethodError: undefined method `password_digest=

Hello,

I did all the steps from the Hartl tutorial but as soon as I do this :

User.create(name: “Michael Hartl”, email: “mhartl@example.com”,password: “foobar”, password_confirmation: “foobar”)

on the rails console, I see this error message :

NoMethodError: undefined method password_digest=' for #<User:0x00000004489fc8> from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activemodel-4.2.0.beta4/lib/active_model/attribute_methods.rb:435:in method_missing’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activemodel-4.2.0.beta4/lib/active_model/secure_password.rb:125:in password=' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:54:in public_send’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:54:in _assign_attribute' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:41:in block in assign_attributes’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:35:in each' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:35:in assign_attributes’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/core.rb:556:in init_attributes' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/core.rb:277:in initialize’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/inheritance.rb:61:in new' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/inheritance.rb:61:in new’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:33:in create' from (irb):4 from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/railties-4.2.0.beta4/lib/rails/commands/console.rb:110:in start’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/railties-4.2.0.beta4/lib/rails/commands/console.rb:9:in start' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/railties-4.2.0.beta4/lib/rails/commands/commands_tasks.rb:68:in console’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/railties-4.2.0.beta4/lib/rails/commands/commands_tasks.rb:39:in run_command!' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/railties-4.2.0.beta4/lib/rails/commands.rb:17:in <top (required)>’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:252:in require' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:252:in block in require’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:237:in load_dependency' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:252:in require’ from /home/ubuntu/workspace/sample_app/bin/rails:8:in <top (required)>' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:246:in load’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:246:in block in load' from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:237:in load_dependency’ from /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies.rb:246:in load' from /usr/local/rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in require’ from /usr/local/rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require’

Roelof

Hello,

I did all the steps from the Hartl tutorial but as soon as I do this :

  User.create(name: "Michael Hartl", email: "mhartl@example.com",password: "foobar", password_confirmation: "foobar")

on the rails console, I see this error message :

Make sure that your Gemfile looks EXACTLY the same as Señor Hartl's. I am betting you are missing the bcrypt library. (It's commented out in a default `rails new` generated site.

# To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0'

Walter

I have exactly what Hartl says.

He says to change my gem file to this :

source 'https://rubygems.org'

gem 'rails',                '4.2.0.rc1'
gem 'bcrypt',               '3.1.7'

And there is no mention about bcrypt-rubt

Roelof

Also did you create the password_digest field in the database as in listing 6.32 and run db:migrate? Check in db/schema.rb to see if that field exists, and make sure it is spelled correctly.

Colin

It may have been renamed since the example I looked at. I haven't used 4.2 yet. (Okay, just checked, and it is the way you describe -- same version, even -- in 4.1. Sorry for the noise.)

Walter

Did you run bundle install after that? It does not look as if you are using 4.2.0.rc1.

And please don't top post, it makes it difficult to follow the thread. Thanks.

Colin

Yep, I did all the steps.

Here is my scheme.rb file :


encoding: UTF-8

This file is auto-generated from the current state of the database. Instead

of editing this file, please use the migrations feature of Active Record to

incrementally modify your database, and then regenerate this schema definition.

Yep, I did all the steps.

Though have not responded to my request that you do not top post. :frowning:

So your Gemfile is exactly the same as in the tutorial? If you think so then please post it here, along with Gemfile.lock

Colin.

Here my gem file :

source ‘https://rubygems.org

gem ‘rails’, ‘4.2.0.beta4’ gem ‘sass-rails’, ‘5.0.0.beta1’ gem ‘bootstrap-sass’, ‘3.2.0.0’ gem ‘uglifier’, ‘2.5.3’ gem ‘coffee-rails’, ‘4.0.1’ gem ‘jquery-rails’, ‘4.0.0.beta2’ gem ‘turbolinks’, ‘2.3.0’ gem ‘jbuilder’, ‘2.2.3’ gem ‘sdoc’, ‘0.4.0’, group: :doc gem ‘arel’, ‘6.0.0.beta2’ gem ‘bcrypt’, ‘3.1.7’

group :development, :test do gem ‘sqlite3’, ‘1.3.9’ gem ‘byebug’, ‘3.4.0’ gem ‘web-console’, ‘2.0.0.beta3’ gem ‘spring’, ‘1.1.3’ end

group :test do gem ‘minitest-reporters’, ‘1.0.5’ gem ‘mini_backtrace’, ‘0.1.3’ gem ‘guard-minitest’, ‘2.3.1’ end

group :production do gem ‘pg’, ‘0.17.1’ gem ‘rails_12factor’, ‘0.0.2’ end

and my gem_file.lock :

remote: https://rubygems.org/ specs: actionmailer (4.2.0.beta4) actionpack (= 4.2.0.beta4) actionview (= 4.2.0.beta4) activejob (= 4.2.0.beta4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.4) actionpack (4.2.0.beta4) actionview (= 4.2.0.beta4) activesupport (= 4.2.0.beta4) rack (~> 1.6.0.beta) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.4) rails-html-sanitizer (~> 1.0, >= 1.0.1) actionview (4.2.0.beta4) activesupport (= 4.2.0.beta4) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.4) rails-html-sanitizer (~> 1.0, >= 1.0.1) activejob (4.2.0.beta4) activesupport (= 4.2.0.beta4) globalid (>= 0.3.0) activemodel (4.2.0.beta4) activesupport (= 4.2.0.beta4) builder (~> 3.1) activerecord (4.2.0.beta4) activemodel (= 4.2.0.beta4) activesupport (= 4.2.0.beta4) arel (>= 6.0.0.beta2, < 6.1) activesupport (4.2.0.beta4) i18n (>= 0.7.0.beta1, < 0.8) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) ansi (1.4.3) arel (6.0.0.beta2) bcrypt (3.1.7) binding_of_caller (0.7.3.pre1) debug_inspector (>= 0.0.1) bootstrap-sass (3.2.0.0) sass (~> 3.2) builder (3.2.2) byebug (3.4.0) columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) celluloid (0.16.0) timers (~> 4.0.0) coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) coffee-script (2.3.0) coffee-script-source execjs coffee-script-source (1.8.0) columnize (0.8.9) debug_inspector (0.0.2) debugger-linecache (1.2.0) erubis (2.7.0) execjs (2.2.2) ffi (1.9.6) formatador (0.2.5) globalid (0.3.0) activesupport (>= 4.1.0) guard (2.9.0) formatador (>= 0.2.4) listen (~> 2.7) lumberjack (~> 1.0) pry (>= 0.9.12) thor (>= 0.18.1) guard-minitest (2.3.1) guard (~> 2.0) minitest (>= 3.0) hike (1.2.3) hitimes (1.2.2) i18n (0.7.0.beta1) jbuilder (2.2.3) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) jquery-rails (4.0.0.beta2) rails-dom-testing (~> 1.0) railties (>= 4.2.0.beta, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) listen (2.8.3) celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) loofah (2.0.1) nokogiri (>= 1.5.9) lumberjack (1.0.9) mail (2.6.3) mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (2.4.3) mini_backtrace (0.1.3) minitest (> 1.2.0) rails (>= 2.3.3) mini_portile (0.6.1) minitest (5.4.3) minitest-reporters (1.0.5) ansi builder minitest (>= 5.0) ruby-progressbar multi_json (1.10.1) nokogiri (1.6.5) mini_portile (~> 0.6.0) pg (0.17.1) pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) rack (1.6.0.beta2) rack-test (0.6.2) rack (>= 1.0) rails (4.2.0.beta4) actionmailer (= 4.2.0.beta4) actionpack (= 4.2.0.beta4) actionview (= 4.2.0.beta4) activejob (= 4.2.0.beta4) activemodel (= 4.2.0.beta4) activerecord (= 4.2.0.beta4) activesupport (= 4.2.0.beta4) bundler (>= 1.3.0, < 2.0) railties (= 4.2.0.beta4) sprockets-rails (~> 3.0.0.beta1) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) rails-dom-testing (1.0.5) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.1) loofah (~> 2.0) rails_12factor (0.0.2) rails_serve_static_assets rails_stdout_logging rails_serve_static_assets (0.0.2) rails_stdout_logging (0.0.3) railties (4.2.0.beta4) actionpack (= 4.2.0.beta4) activesupport (= 4.2.0.beta4) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.0) rb-fsevent (0.9.4) rb-inotify (0.9.5) ffi (>= 0.5.0) rdoc (4.1.2) json (~> 1.4) ruby-progressbar (1.7.0) sass (3.4.9) sass-rails (5.0.0.beta1) railties (>= 4.0.0, < 5.0) sass (~> 3.2) sprockets (~> 2.12) sprockets-rails (>= 2.0, < 4.0) sdoc (0.4.0) json (~> 1.8) rdoc (~> 4.0, < 5.0) slop (3.6.0) spring (1.1.3) sprockets (2.12.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sprockets-rails (3.0.0.beta1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (~> 2.8) sqlite3 (1.3.9) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) timers (4.0.1) hitimes turbolinks (2.3.0) coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.5.3) execjs (>= 0.3.0) json (>= 1.8.0) web-console (2.0.0.beta3) activemodel (~> 4.0) binding_of_caller (= 0.7.3.pre1) railties (~> 4.0) sprockets-rails (>= 2.0, < 4.0)

PLATFORMS ruby

DEPENDENCIES arel (= 6.0.0.beta2) bcrypt (= 3.1.7) bootstrap-sass (= 3.2.0.0) byebug (= 3.4.0) coffee-rails (= 4.0.1) guard-minitest (= 2.3.1) jbuilder (= 2.2.3) jquery-rails (= 4.0.0.beta2) mini_backtrace (= 0.1.3) minitest-reporters (= 1.0.5) pg (= 0.17.1) rails (= 4.2.0.beta4) rails_12factor (= 0.0.2) sass-rails (= 5.0.0.beta1) sdoc (= 0.4.0) spring (= 1.1.3) sqlite3 (= 1.3.9) turbolinks (= 2.3.0) uglifier (= 2.5.3) web-console (= 2.0.0.beta3)

Roelof

> Yep, I did all the steps.

Though have not responded to my request that you do not top post. :frowning:

So your Gemfile is exactly the same as in the tutorial? If you think so then please post it here, along with Gemfile.lock

Colin.

Here my gem file :

source 'https://rubygems.org' gem 'rails', '4.2.0.beta4'

Are you following https://www.railstutorial.org/book/modeling_users#sec-creating_and_authenticating_a_user? Listing 6.33 shows a different version of Rails (as I have already pointed out). Please check that your Gemfile is /exactly/ the same as in the tutorial, then run bundle update. There is no guarantee that is the issue but you must rule it out first.

Colin

You are right. The version changed in the time that I follow that tutorial.

I now facing this problem :

Bundler could not find compatible versions for gem “arel”: In Gemfile: rails (= 4.2.0.rc1) ruby depends on activerecord (= 4.2.0.rc1) ruby depends on arel (~> 6.0) ruby

arel (6.0.0.beta2)

Roelof

Edit 1 : I can delete the arel version but then I will run into this problem : https://groups.google.com/forum/#!topic/rubyonrails-talk/9KY84ScB_6A

> > >> >> > Yep, I did all the steps. >> >> Though have not responded to my request that you do not top post. :frowning: >> >> So your Gemfile is exactly the same as in the tutorial? If you think >> so then please post it here, along with Gemfile.lock >> >> Colin. > > > > Here my gem file : > > source 'https://rubygems.org' > gem 'rails', '4.2.0.beta4'

Are you following

https://www.railstutorial.org/book/modeling_users#sec-creating_and_authenticating_a_user? Listing 6.33 shows a different version of Rails (as I have already pointed out). Please check that your Gemfile is /exactly/ the same as in the tutorial, then run bundle update. There is no guarantee that is the issue but you must rule it out first. ...

You are right. The version changed in the time that I follow that tutorial. I now facing this problem :

Bundler could not find compatible versions for gem "arel":

Did you check, as I have suggested several times that your Gemfile is exactly the same as required in the tutorial?

Yes, I am

I am also learning now…Have you tried “has_secure_password” in the User model.