RubyonRails4アプリケーションプログラミング山田さん版2018年10月1日
Windows環境にRuby,SQLite等をインストールと今日のエラー
Windows環境にて作成
Windows環境にRuby,SQLite等をインストール。
インストール方法は書籍に記載されている。
Ruby2.5、rails4.0.2をインストールした。しかし、どうもこの2.5バージョンは最新すぎてうまくいかない。なので、途中で2.4.4に切り替えた
c:\data内にアプリを作成
rails new railbookでディレクトリが作られる
c:\data\railbook
Rubyとかをインストールしたときに
MSYS2のアップデートとMINGWとの連携を忘れていた。
そのため
ridk installとDOSプロンプトで実行したら、インストーラが起動した。
そこで2と3を実行しました。
rails server
でWeblickが実行できずエラー
c:\data\railbook>rails server
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.0.2/lib/active_support/values/time_zone.rb:282: warning: circular argument reference – now
Traceback (most recent call last):
16: from bin/rails:4:in
require’
15: from bin/rails:4:in
14: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in
tap’
13: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in
12: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-4.0.2/lib/rails/commands.rb:74:in block in
require’
11: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-4.0.2/lib/rails/commands.rb:74:in
10: from c:/data/railbook/config/application.rb:7:in
require’
9: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler.rb:114:in
8: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler/runtime.rb:65:in require'
each’
7: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler/runtime.rb:65:in
6: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler/runtime.rb:76:in block in require'
each’
5: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler/runtime.rb:76:in
4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler/runtime.rb:81:in block (2 levels) in require'
require’
3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bundler-1.16.5/lib/bundler/runtime.rb:81:in
2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:2:in
rescue in
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in require': cannot load such file -- sqlite3/sqlite3_native (LoadError)
まず、sqlite3がLOADERRORなのでネットで調べる
https://www.oiax.jp/books/can_not_load_sqlite3_native.html
するとDLLが足りていないみたい。
C:\Ruby25-x64\binフォルダに
DLLをコピーした
そして
rails server
でも同じエラー
調べると
SQLITE3がruby2.5に対応していないからだそうです。2.4に下げるか?
でも他にも解決方法があるようです。
https://akeyfn.xyz/sitesakusei/sqlite3sqlite3_native-loaderror/
C:\Ruby25-x64\lib\ruby\gems\2.5.0\specificationsにある
sqlite3-1.3.13-x64-mingw32.gemspec
を開きます。
多分バージョンがお使いの環境で違うので似たようなファイルをエディタで開きます。
s.require_paths = ["lib".freeze]
↓
s.require_paths = ["lib/splite3_native".freeze]
に変更して保存します。
これでもだけだったので、もとにlibに戻した
再度
rails serverとする
でもだめ
C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13-x64-mingw32\lib
sqlite3.rb
を見ると
「
begin
RUBY_VERSION =~ /(\d+\.\d+)/
require "sqlite3/#{$1}/sqlite3_native"
rescue LoadError
require 'sqlite3/sqlite3_native'
end
」
となっている。ここがnativeになっているからここが元凶だ。
調べるとnativeがない
#require "sqlite3/#{$1}/sqlite3_native"
require "sqlite3/#{$1}/sqlite3
なのでコメントにしてみた
でもだめ
そこで
#require "sqlite3/#{$1}/sqlite3_native"
require "sqlite3"
sqlite3だけにした
今度は別のエラー
c:\data\railbook>rails server
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.0.2/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.0.2/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.0.2/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
Traceback (most recent call last):
bin/rails: stack level too deep (SystemStackError)
c:\data\railbook>dir
調べるとrailsのバージョンと相性が良くないらしいので
4.2.8にしてみる
Gemfileを修正
gem 'rails', '4.2.8'
そして
bundle update rails
実行
するとまた別のエラーが発生した
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/tzinfo-1.2.5/lib/tzinfo/data_source.rb:179:in create_default_data_source’
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/tzinfo-1.2.5/lib/tzinfo/data_source.rb:182:in rescue in create_default_data_source': No source of timezone data could be found. (TZInfo::DataSourceNotFound)
Please refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error.
こりゃ困ったな。
多分もっとエラーがでそうなので、
ruby2.5から2.4.4にダウングレードできるかを調べる。
https://rubyinstaller.org/downloads/
から2.4.4をダウンロードする。
今日はここまで2018年10月2日
これでだめなら、SQLITEではなくて、MYSQLにする
ruby2.4.4をインストールしました。
C:\Users\mased>rails -v
Rails 4.2.8
C:\Users\mased>ruby -v
ruby 2.4.4p296 (2018-03-28 revision 63013) [x64-mingw32]
c:\dataフォルダに移動して、
rails new railbookで実行
Bundle complete! 12 Gemfile dependencies, 60 gems now installed.
Use bundle info [gemname] to see where a bundled gem is installed.
Post-install message from sass:
Ruby Sass is deprecated and will be unmaintained as of 26 March 2019.
* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
primary implementation: https://sass-lang.com/install
* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
sassc gem: https://github.com/sass/sassc-ruby#readme
* For more details, please refer to the Sass blog:
http://sass.logdown.com/posts/7081811
sassはまた後でいいかな。
今日はここまで。
・今度は成功
c:\data\railbook>rails server
=> Booting WEBrick
=> Rails 4.2.8 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
[2018-10-02 20:41:48] INFO WEBrick 1.4.2
[2018-10-02 20:41:48] INFO ruby 2.5.1 (2018-03-29) [x64-mingw32]
[2018-10-02 20:41:48] INFO WEBrick::HTTPServer#start: pid=10728 port=3000
でもRubyのバージョンが違う。2.4.4のはずが、前回インストールした2.5.1になってる。
異なるバージョンを管理するpikを使う
と思ったらバージョンが古くて新しいRUBYに対応していなそう。
今度はURUだ
C:\tool\uru-0.8.5-windows-x86>uru_rt admin install
---> Installing uru into C:\tool\uru-0.8.5-windows-x86
C:\tool\uru-0.8.5-windows-x86>uru admin add C:\Ruby24-x64\bin --tag ruby24
---> Registered ruby at C:\Ruby24-x64\bin as
ruby24
C:\tool\uru-0.8.5-windows-x86>uru admin add C:\Ruby25-x64\bin --tag ruby25
---> Registered ruby at C:\Ruby25-x64\bin as
ruby25
これで登録した。
切り替えはタグ名で
C:\tool\uru-0.8.5-windows-x86>uru ruby24
---> now using ruby 2.4.4-p296 tagged as ruby24
C:\tool\uru-0.8.5-windows-x86>
これで切り替わったかと思ったらまだ
だめだ。
Ruby2.5.1を見てる。
環境変数で2.5.1のパスを削除したけど
ruby -vでみると2.4.4なのに
WEBRICKでは2.5.1になる。
PCを再起動してみる。
または再度railbookフォルダを削除してみる。
次はここから
再起動して
c:\data\railsbookを削除して
再度
rails newを実行すると実行できなくなった。
そこで
rails -v
とするとバージョンが表示されない。
どうやら、インストールされていない状態になっている。
再度
gem install rails -v 4.2.8で
railsをインストールした。
2018年10月2日、21時42分
そしてc:\data\railbook>rails server
=> Booting WEBrick
=> Rails 4.2.8 application starting in development on http://localhost:3000
=> Run rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2018-10-02 21:46:20] INFO WEBrick 1.3.1
[2018-10-02 21:46:20] INFO ruby 2.4.4 (2018-03-28) [x64-mingw32]
[2018-10-02 21:46:20] INFO WEBrick::HTTPServer#start: pid=4748 port=3000
起動した。
エラーがない。
長い。
そしてブラウザで無事表示できた
Welcome aboard
You’re riding Ruby on Rails!
結論
ruby 2.4.4
rails 4.2.8
SQLiteで構築しました。
P28から
本を読んでいくと途中で、解説なのかチュートリアルなのかわからなくなったので、別の書籍で勉強する。
今度は、
パーフェクトRubyOnRailsすがわらまさのり著他