開発環境
OS:Windows7
Ruby: 2.4.0p0
rails: 5.0.2
rails serverが起動しない
Gemfileに
gem 'bcrypt'
と追加したらServerが立たなくなった
bundle exec rails s
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in `require': cannot load such file -- bcrypt_ext (LoadError)
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in `rescue in <
top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:12:in `<top (requi
red)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `block (2 leve
ls) in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `block in requ
ire'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler.rb:107:in `require'
from C:/work/qines_autosar_purosess_tool/config/application.rb:7:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in
`require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in
`block in server'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in
`tap'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in
`server'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in
`run_command!'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required
)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
ぐぬぬ...
とここに解決策が乗ってるな
Bcrypt 3.1.11 - Cannot load file on Windows
(抜粋)
I solve it with uninstall all bcrypt gem versions with gem uninstall bcrypt and
select option 3 (if exist) and uninstall all bcrypt-ruby gem versions with gem uninstall
bcrypt-ruby and select option 3 (if exist) then install bcrypt using gem install bcrypt
--platform=ruby then add this line gem 'bcrypt', platforms: :ruby to Gemfile, that is it :D.
ためしに、やってみた。
> gem uninstall bcrypt
Successfully uninstalled bcrypt-3.1.11-x64-mingw32
>
> gem uninstall bcrypt-ruby
>
> gem install bcrypt --platform=ruby
Fetching: bcrypt-3.1.11.gem (100%)
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
Successfully installed bcrypt-3.1.11
Parsing documentation for bcrypt-3.1.11
Installing ri documentation for bcrypt-3.1.11
Done installing documentation for bcrypt after 1 seconds
1 gem installed
>
> bundle exec rails s
=> Booting Puma
=> Rails 5.0.2 application starting in development on http://0.0.0.0:5000
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.8.0 (ruby 2.4.0-p0), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:5000
Use Ctrl-C to stop
無事に起動した!
LoadError発生
しかし、エラーはそれだけではなかった。。。
というのも、ページにアクセスすると...
LoadError in LoginController#index
cannot load such file -- bcrypt
Extracted source (around line #3):
1 class User < ActiveRecord::Base
2
3 has_secure_password
4
5 def self.new_remember_token
6 SecureRandom.urlsafe_base64
うーんうまく動いていない...
そこで下記記事を見つける
'require': cannot load such file -- bcrypt_ext (LoadError)と出たときの対処法
記事のとおりにGemfileに
gem 'bcrypt-ruby', '3.1.1.rc1', :require => 'bcrypt'
を追加してbundle update
すると無事にページが表示された!