问题描述
尝试创建密码时,我在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 (将#修改为@)