質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

2回答

3309閲覧

cannot load such file -- bcryptと表示されてしまいます。

ninpig04

総合スコア33

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

1クリップ

投稿2017/11/30 17:45

編集2017/12/01 13:28

現在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)と表示されているのでインストールはされているはずです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

では次に,Rails と無関係に bcrypt が使えるかどうか確かめてみたいと思います。

次の結果はどうなるでしょうか。

ruby -r bcrypt -e 'p BCrypt::Password.create("hoge")'

こちらも,念のため,その Rails プロジェクトのディレクトリーでやってみてください。
また,念のため sudo ありと無しと両方試してみてください。

なんか長ったらしいデタラメな英数字列が表示されたら,インストールされた bcrypt がちゃんと働く証拠です。

投稿2017/12/02 01:53

scivola

総合スコア2108

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

bcrypt がインストールできているかがポイントだと思うので,まずそれを確かめたいと思います。

その Rails プロジェクトのディレクトリーで

gem list bcrypt

および

sudo gem list bcrypt

をやってみてください。

どちらでやっても出てきますか?

投稿2017/11/30 23:25

scivola

総合スコア2108

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ninpig04

2017/12/01 11:12

どちらで行なってもbcrypt (3.1.11)とでてきます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問