LoginSignup
7
3

More than 3 years have passed since last update.

<Windows>Ruby on Rails チュートリアルでのつまづきポイントまとめ

Last updated at Posted at 2019-07-21

Railsチュートリアル第4版をWindows環境で一通り終えた。

これから取り組む方のために、Windows環境でチュートリアルを進める際につまづきやすいポイントをまとめておきます。※基本的に解決法のみの記載とします。

第3章

3.3.1 最初のテスト

エラー発生時:チュートリアル中初めての「rails test」

エラー内容
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/platform.rb:144:in
`assert_executable': not executable: "C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/chromedriver-helper-2.1.1/bin/chromedriver-helper" (Selenium::WebDriver::Error::WebDriverError)

解決法

chromedriver-helperに問題があるようだ。
調べると、

chromedriver-helperは2019/3/31よりサポートされなくなったようだ。代わりにwebdriversが使えるとのこと。
チュートリアルの中で示されているgemfileの一部を書き換える

Gemfile
group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
-  gem 'chromedriver-helper'
+  gem 'webdrivers'
  gem 'rails-controller-testing', '1.0.2'
  gem 'minitest',                 '5.10.3'
  gem 'minitest-reporters',       '1.1.14'
  gem 'guard',                    '2.13.0'
  gem 'guard-minitest',           '2.4.4'
end
console
bundle install

これで実行できる。

console
Run options: --seed 61639

# Running:

..

Finished in 3.028772s, 0.6603 runs/s, 0.6603 assertions/s.

2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
05:01:28 - INFO - Run 'gem install win32console' to use color on Windows
]2;[Minitest results] 2 tests

第6章ユーザーのモデルを作成する

6.3.2 ユーザーがセキュアなパスワードを持っている

エラー発生時:bcryptインストール後、初めてのrails test実行時。

エラー内容
cannot load such file -- bcrypt_ext

解決法※コメント欄に指摘・追記あり!※2回

※以下を試される前に、コメント欄追記をぜひ参考ください!※
追記概要:「-x64-mingw32」がついたbcryptをアンインストールするだけで動作する環境の方もいらっしゃるようです。私と同様に初心者の方はシンプルな方法からぜひお試しください。
再度追記いたしました。

指示通りに行っていれば、C:\Ruby23\lib\ruby\gems\2.6.0\gems\に「bcrypt-3.1.11-x64-mingw32」があるはず。
以下を実行する。

console
gem install bcrypt --platform ruby

これでbcrypt-3.1.13がインストールされる。

現在、bcrypt-3.1.11-x64-mingw32とbcrypt-3.1.13の2つのフォルダがC:\Ruby23\lib\ruby\gems\2.6.0\gems\内にある状態である。

次に、bcrypt-3.1.13の中の/lib/bcrypt_ext.soをコピーして、bcrypt-3.1.11-x64-mingw32の中の/lib/にペーストする。これで再度test。

console
rails test

「rails db:migrate RAILS_ENV=test 」を実行しろと言われるかもしれない。その場合は実行してから再度rails testを行う。

参考:

第7章ユーザー登録

7.4.3 実際のユーザー登録

エラー発生時:rails db:migrate:reset実行時

エラー内容
Couldn't drop database 'db/development.sqlite3'
rails aborted! 
Errno::EACCES: Permission denied

解決法

Windowsには「自らがアクセスしているファイルを削除できない」という仕様がある。そもそも「rails db:migrate:reset」というコマンドを使うことができないということだ。

したがって代替法をとる。
直接development.sqlite3を削除後、

console
rails db:migrate

を実行すれば同じ結果が得られる。

参考:
- db:migrate:reset でエラーが出ます
- WindowsにてRails 5でdb:migrate:resetをしたらエラーになったときの解決法

第10章

10.4.3 ユーザー削除のテスト

エラー発生時:windows環境でのpumaサーバーの実行

エラー内容
worker mode not supported on ruby on this platform worker windows puma

解決法

config/puma.rbの1行目をコメントアウトする。

config/puma.rb
#workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
省略

参考:
- rails sができない(開発環境から本番環境)
- Deploying Rails Applications with the Puma Web Server

第13章ユーザーのマイクロポスト

13.4.3 画像のリサイズ

エラー発生時:windows環境へのimagemagickのインストールと実行。

エラー内容
メモし忘れました。

インストール法の記事はたくさんありますが、以下サイトが簡潔。

💉 How To Install The RMagick 💉 #RubyOnRails Gem on Windows 7/8/10 (ImageMagick 6.9.6 Q16-HDRI)

7
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3