(Rails) : NoMethodError: undefined method cost' for BCrypt::Engine:Class
bcrypt-ruby, ruby-on-rails-4
Solution
Add bcrypt-ruby to your Gemfile as specified below:
gem 'bcrypt-ruby', '3.1.2'
then run bundle update from your project root directory and bundle install
Problem
When I learn "Ruby on Rails Tutorial", and I want to create a User on console: ``` irb(main):001:0> User.create(name:"gsky",email:"k@q.com", irb(main):002:1* password:"aaaaaa",password_confirmation:"aaaaaa") ``` then, I getting the following error message: ``` NoMethodError: undefined method cost' for BCrypt::Engine:Class from D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activemodel-4. 0.2/lib/active_model/secure_password.rb:104:inpassword=' from D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4 .0.2/lib/active_record/attribute_assignment.rb:42:in public_send' ``` This is user model: ``` class User < ActiveRecord::Base before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } has_secure_password validates :password, length: { minimum: 6 } end ```