微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NameError未初始化的常量BCrypt

如何解决NameError未初始化的常量BCrypt

尝试创建密码时,我在Rails控制台中始终收到此错误

BCrypt::Password.create("foobar")
NameError (uninitialized constant BCrypt)

我的gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.1'


# Bundle edge Rails instead: gem 'rails',github: 'rails/rails'
gem 'rails','~> 6.0.3','>= 6.0.3.2'
# Use postgresql as the database for Active Record
gem 'pg','>= 0.18','< 2.0'
# Use Puma as the app server
gem 'puma','~> 4.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder','~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis','~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt','~> 3.1.7' 

# Use Active Storage variant
# gem 'image_processing','~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap','>= 1.4.2',require: false

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS),making cross-origin AJAX possible
gem 'rack-cors'

group :development,:test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug',platforms: [:mri,:mingw,:x64_mingw]
end

group :development do
  gem 'listen','~> 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen','~> 2.0.0'
end

# Windows does not include zoneinfo files,so bundle the tzinfo-data gem
gem 'tzinfo-data',platforms: [:mingw,:mswin,:x64_mingw,:jruby]
gem "active_model_serializers"
gem "jwt"

我的用户模型:

class User < ApplicationRecord
    has_secure_password
    belongs_to :school
    has_many :user_courses
    has_many :courses,through: :user_courses  
    has_many :user_resources
    has_many :resources,through: :user_resources
  end

我的用户架构:

  create_table "users",force: :cascade do |t|
    t.string "name"
    t.string "category"
    t.integer "school_id"
    t.boolean "permission",default: true
    t.datetime "created_at",precision: 6,null: false
    t.datetime "updated_at",null: false
  end

任何想法为何会发生此错误?我也尝试在用户模型中要求使用bcrypt,但还是没有运气。我也尝试了Password.new,但还是没有。不知道在这时还需要做什么,将不胜感激!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。