現在Ruby on Railsでアプリ開発をしているのですが、パスワードを暗号化しようとしてエラーが表示されてしまいました。
エラーの内容は以下の通りです
LoadError in PostsController#new
cannot load such file -- bcrypt
class User < ApplicationRecord
has_secure_password validates :name, {presence: true} validates :email, {presence: true, uniqueness: true}
Rails.root: /Users/comp/Desktop/tweet_app
Application Trace | Framework Trace | Full Trace
app/models/user.rb:3:in <class:User>' app/models/user.rb:1:in
<top (required)>'
app/controllers/application_controller.rb:5:in `set_current_user'
This error occurred while loading the following files:
bcrypt
Request
Parameters:
None
Toggle session dump
Toggle env dump
Response
Headers:
None
x
もとのコードは次のようになります
class User < ApplicationRecord
has_secure_password validates :name, {presence: true} validates :email, {presence: true, uniqueness: true} def posts return Post.where(user_id: self.id) end
end
おそらくgemfileの中のbcryptに問題があるのではないかと思っています。gem 'bcrypt'を追加したのですが。。。
bundle installもしっかり実行しました。それでもダメだったためsudo bundle update springも実行し、ターミナルには次のように表示されました。
Fetching gem metadata from https://rubygems.org/...............
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies....
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Fetching activesupport 5.0.3 (was 5.0.6)
Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.
Password:
Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.
Password:
Installing activesupport 5.0.3 (was 5.0.6)
Using builder 3.2.3
Using erubis 2.7.0
Using mini_portile2 2.3.0
Using nokogiri 1.8.1
Using rails-dom-testing 2.0.3
Using crass 1.0.3
Using loofah 2.1.1
Using rails-html-sanitizer 1.0.3
Fetching actionview 5.0.3 (was 5.0.6)
Installing actionview 5.0.3 (was 5.0.6)
Using rack 2.0.3
Using rack-test 0.6.3
Fetching actionpack 5.0.3 (was 5.0.6)
Installing actionpack 5.0.3 (was 5.0.6)
Using nio4r 2.1.0
Using websocket-extensions 0.1.3
Using websocket-driver 0.6.5
Fetching actioncable 5.0.3 (was 5.0.6)
Installing actioncable 5.0.3 (was 5.0.6)
Using globalid 0.4.1
Fetching activejob 5.0.3 (was 5.0.6)
Installing activejob 5.0.3 (was 5.0.6)
Using mini_mime 1.0.0
Using mail 2.7.0
Fetching actionmailer 5.0.3 (was 5.0.6)
Installing actionmailer 5.0.3 (was 5.0.6)
Fetching activemodel 5.0.3 (was 5.0.6)
Installing activemodel 5.0.3 (was 5.0.6)
Using arel 7.1.4
Fetching activerecord 5.0.3 (was 5.0.6)
Installing activerecord 5.0.3 (was 5.0.6)
Fetching bcrypt 3.1.11
Installing bcrypt 3.1.11 with native extensions
Using bundler 1.16.0
Fetching byebug 9.0.6 (was 9.1.0)
Installing byebug 9.0.6 (was 9.1.0) with native extensions
Fetching coderay 1.1.2
Installing coderay 1.1.2
Fetching debug_inspector 0.0.3
Installing debug_inspector 0.0.3 with native extensions
Using execjs 2.7.0
Using ffi 1.9.18
Using method_source 0.9.0
Using thor 0.20.0
Fetching railties 5.0.3 (was 5.0.6)
Installing railties 5.0.3 (was 5.0.6)
Fetching jquery-rails 4.2.2 (was 4.3.1)
Installing jquery-rails 4.2.2 (was 4.3.1)
Using rb-fsevent 0.10.2
Using rb-inotify 0.9.10
Using listen 3.0.8
Fetching pry 0.11.3
Installing pry 0.11.3
Fetching pry-rails 0.3.4
Installing pry-rails 0.3.4
Fetching puma 3.6.2 (was 3.11.0)
Installing puma 3.6.2 (was 3.11.0) with native extensions
Using sprockets 3.7.1
Using sprockets-rails 3.2.1
Fetching rails 5.0.3 (was 5.0.6)
Installing rails 5.0.3 (was 5.0.6)
Using sass-listen 4.0.0
Using sass 3.5.3
Using tilt 2.0.8
Fetching sass-rails 5.0.6 (was 5.0.7)
Installing sass-rails 5.0.6 (was 5.0.7)
Fetching spring 2.0.1 (was 2.0.2)
Installing spring 2.0.1 (was 2.0.2)
Using spring-watcher-listen 2.0.1
Using sqlite3 1.3.13
Using turbolinks-source 5.0.3
Using turbolinks 5.0.1
Fetching uglifier 3.0.4 (was 3.2.0)
Installing uglifier 3.0.4 (was 3.2.0)
Fetching web-console 3.4.0 (was 3.5.1)
Installing web-console 3.4.0 (was 3.5.1)
Bundler attempted to update spring but its version regressed from 2.0.2 to 2.0.1
Bundle updated!
その後、bundle installを実行した結果は以下の通りです
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Using activesupport 5.0.3
Using builder 3.2.3
Using erubis 2.7.0
Using mini_portile2 2.3.0
Using nokogiri 1.8.1
Using rails-dom-testing 2.0.3
Using crass 1.0.3
Using loofah 2.1.1
Using rails-html-sanitizer 1.0.3
Using actionview 5.0.3
Using rack 2.0.3
Using rack-test 0.6.3
Using actionpack 5.0.3
Using nio4r 2.1.0
Using websocket-extensions 0.1.3
Using websocket-driver 0.6.5
Using actioncable 5.0.3
Using globalid 0.4.1
Using activejob 5.0.3
Using mini_mime 1.0.0
Using mail 2.7.0
Using actionmailer 5.0.3
Using activemodel 5.0.3
Using arel 7.1.4
Using activerecord 5.0.3
Using bcrypt 3.1.11
Using bundler 1.16.0
Using byebug 9.0.6
Using coderay 1.1.2
Using debug_inspector 0.0.3
Using execjs 2.7.0
Using ffi 1.9.18
Using method_source 0.9.0
Using thor 0.20.0
Using railties 5.0.3
Using jquery-rails 4.2.2
Using rb-fsevent 0.10.2
Using rb-inotify 0.9.10
Using listen 3.0.8
Using pry 0.11.3
Using pry-rails 0.3.4
Using puma 3.6.2
Using sprockets 3.7.1
Using sprockets-rails 3.2.1
Using rails 5.0.3
Using sass-listen 4.0.0
Using sass 3.5.3
Using tilt 2.0.8
Using sass-rails 5.0.6
Using spring 2.0.1
Using spring-watcher-listen 2.0.1
Using sqlite3 1.3.13
Using turbolinks-source 5.0.3
Using turbolinks 5.0.1
Using uglifier 3.0.4
Using web-console 3.4.0
Bundle complete! 14 Gemfile dependencies, 62 gems now installed.
Use bundle info [gemname]
to see where a bundled gem is installed.
os:mac
Ruby 2.3.1
RoR 5.0.0
よろしくお願いします
bcrypt (3.1.11)と表示されているのでインストールはされているはずです
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。