ActiveSupport:Module エラー Rails4のプロジェクトをrails sしたい

  • このエントリーをはてなブックマークに追加

こんにちはRyujiです。

いつも、まこなり社長の動画をみて、自分の行動の見直しをしています。

さて、今回はRails sでサーバを立ち上げたいです。早速やっていきましょう!

オススメの動画です。

Contents

おもむろにrails s

前回はbundle installまでやりましたね

絶対エラー出ると思うけど、とりあえずrails sでサーバを立ち上げてみようと思います。

~/w/threesession [setting-project-restart] » rails s                                                                                 21:38:34
Phantomjs does not appear to be installed in /Users/ratovia/.phantomjs/2.1.1/darwin/bin/phantomjs, installing!
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 16.3M  100 16.3M    0     0  2465k      0  0:00:06  0:00:06 --:--:-- 3485k
Archive:  phantomjs-2.1.1-macosx.zip
   creating: phantomjs-2.1.1-macosx/
   creating: phantomjs-2.1.1-macosx/bin/
  inflating: phantomjs-2.1.1-macosx/bin/phantomjs  
  inflating: phantomjs-2.1.1-macosx/ChangeLog  
   creating: phantomjs-2.1.1-macosx/examples/
  inflating: phantomjs-2.1.1-macosx/examples/arguments.js  
  inflating: phantomjs-2.1.1-macosx/examples/child_process-examples.js  
  inflating: phantomjs-2.1.1-macosx/examples/colorwheel.js  
  inflating: phantomjs-2.1.1-macosx/examples/countdown.js  
  inflating: phantomjs-2.1.1-macosx/examples/detectsniff.js  
  inflating: phantomjs-2.1.1-macosx/examples/echoToFile.js  
  inflating: phantomjs-2.1.1-macosx/examples/features.js  
  inflating: phantomjs-2.1.1-macosx/examples/fibo.js  
 extracting: phantomjs-2.1.1-macosx/examples/hello.js  
  inflating: phantomjs-2.1.1-macosx/examples/injectme.js  
  inflating: phantomjs-2.1.1-macosx/examples/loadspeed.js  
  inflating: phantomjs-2.1.1-macosx/examples/loadurlwithoutcss.js  
  inflating: phantomjs-2.1.1-macosx/examples/modernizr.js  
  inflating: phantomjs-2.1.1-macosx/examples/module.js  
  inflating: phantomjs-2.1.1-macosx/examples/netlog.js  
  inflating: phantomjs-2.1.1-macosx/examples/netsniff.js  
  inflating: phantomjs-2.1.1-macosx/examples/openurlwithproxy.js  
  inflating: phantomjs-2.1.1-macosx/examples/outputEncoding.js  
  inflating: phantomjs-2.1.1-macosx/examples/page_events.js  
  inflating: phantomjs-2.1.1-macosx/examples/pagecallback.js  
  inflating: phantomjs-2.1.1-macosx/examples/phantomwebintro.js  
  inflating: phantomjs-2.1.1-macosx/examples/post.js  
  inflating: phantomjs-2.1.1-macosx/examples/postjson.js  
  inflating: phantomjs-2.1.1-macosx/examples/postserver.js  
  inflating: phantomjs-2.1.1-macosx/examples/printenv.js  
  inflating: phantomjs-2.1.1-macosx/examples/printheaderfooter.js  
  inflating: phantomjs-2.1.1-macosx/examples/printmargins.js  
  inflating: phantomjs-2.1.1-macosx/examples/rasterize.js  
  inflating: phantomjs-2.1.1-macosx/examples/render_multi_url.js  
  inflating: phantomjs-2.1.1-macosx/examples/responsive-screenshot.js  
  inflating: phantomjs-2.1.1-macosx/examples/run-jasmine.js  
  inflating: phantomjs-2.1.1-macosx/examples/run-jasmine2.js  
  inflating: phantomjs-2.1.1-macosx/examples/run-qunit.js  
  inflating: phantomjs-2.1.1-macosx/examples/scandir.js  
  inflating: phantomjs-2.1.1-macosx/examples/server.js  
  inflating: phantomjs-2.1.1-macosx/examples/serverkeepalive.js  
  inflating: phantomjs-2.1.1-macosx/examples/simpleserver.js  
  inflating: phantomjs-2.1.1-macosx/examples/sleepsort.js  
  inflating: phantomjs-2.1.1-macosx/examples/stdin-stdout-stderr.js  
  inflating: phantomjs-2.1.1-macosx/examples/universe.js  
  inflating: phantomjs-2.1.1-macosx/examples/unrandomize.js  
  inflating: phantomjs-2.1.1-macosx/examples/useragent.js  
  inflating: phantomjs-2.1.1-macosx/examples/version.js  
  inflating: phantomjs-2.1.1-macosx/examples/waitfor.js  
  inflating: phantomjs-2.1.1-macosx/examples/walk_through_frames.js  
  inflating: phantomjs-2.1.1-macosx/LICENSE.BSD  
  inflating: phantomjs-2.1.1-macosx/README.md  
  inflating: phantomjs-2.1.1-macosx/third-party.txt  

Successfully installed phantomjs. Yay!
Removed temporarily downloaded files.
=> Booting WEBrick
=> Rails 5.2.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Exiting
Traceback (most recent call last):
	57: from bin/rails:4:in `<main>'
	56: from bin/rails:4:in `require'
	55: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
	54: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
	53: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
	52: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
	51: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
	50: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
	49: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `perform'
	48: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `tap'
	47: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:147:in `block in perform'
	46: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:51:in `start'
	45: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:89:in `log_to_stdout'
	44: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/server.rb:354:in `wrapped_app'
	43: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:27:in `app'
	42: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/server.rb:219:in `app'
	41: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/server.rb:319:in `build_app_and_options_from_config'
	40: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/builder.rb:40:in `parse_file'
	39: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/builder.rb:49:in `new_from_string'
	38: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/builder.rb:49:in `eval'
	37: from config.ru:in `<main>'
	36: from config.ru:in `new'
	35: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
	34: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
	33: from config.ru:3:in `block in <main>'
	32: from config.ru:3:in `require'
	31: from /Users/ratovia/workspace/threesession/config/environment.rb:5:in `<top (required)>'
	30: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!'
	29: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers'
	28: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
	27: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
	26: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
	25: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
	24: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
	23: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
	22: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:415:in `each_strongly_connected_component_from'
	21: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:415:in `call'
	20: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `tsort_each_child'
	19: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `each'
	18: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
	17: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
	16: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
	15: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	14: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
	13: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers'
	12: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run'
	11: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
	10: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `block in <class:Engine>'
	 9: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `each'
	 8: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
	 7: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/engine.rb:656:in `load_config_initializer'
	 6: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb:170:in `instrument'
	 5: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/engine.rb:657:in `block in load_config_initializer'
	 4: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load'
	 3: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
	 2: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `block in load'
	 1: from /Users/ratovia/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load'
/Users/ratovia/workspace/threesession/config/initializers/new_framework_defaults.rb:23:in `<top (required)>': undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)

はい、一つずつ見ていきます。

Phantomjs does not appear to be installed in /Users/ratovia/.phantomjs/2.1.1/darwin/bin/phantomjs, installing!

Phantomjsというものがインストールされていないので、インストールします!って言ってまして、後ろで実際にインストール完了していますね。

Phantomjsってなんだよ!ってことで調べてきました。

https://qiita.com/kingston/items/82cd6978b4ac7afa6fdf

どうやら、ターミナルで動作するブラウザ(ヘッドレスブラウザ)なようですね。

Gemfileやtestファイルを見てみると、JavaScriptのテストを書こうと思って、過去の自分が導入していたみたいです。

PhantomJSの開発は終了し、リポジトリはアーカイブ化されました。

もう終わった技術とのこと、これから使っていくメリットは特になさそうですね。

JavaScriptのテスト、代替手段は?

いくつか方法があります。

  • mocha + chai
  • karma + jasmine
  • jest

フォルダを見てみると、テストはほとんど書いていない上に、復活させるという趣旨と少し違うので、

今回はPhamtomjsを廃止し、代替手段は用意しない。

ことにします。

Phamtom.jsの削除

bundle install & bundle updateしてGemfileからphamtomjsを削除しました。

~/w/threesession [setting-project-restart]× » gem list | grep phantomjs                            14:49:02
phantomjs (2.1.1.0)

Gem listにも残っていたので、削除しました。

~/w/threesession [setting-project-restart]× » gem uninstall phantomjs                                                                -1- 14:48:18
Successfully uninstalled phantomjs-2.1.1.0

これでスッキリですね!

ActiveSupport:Module (NoMethodError)

/Users/ratovia/workspace/threesession/config/initializers/new_framework_defaults.rb:23:in `<top (required)>': undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)

さて、もう一つエラーが起きていましたね。

調べると、Railsのバージョンをあげた際に、Rails4にある後方互換のメソッドがRails5で定義されていないってエラーのようですね。該当行をコメントアウトします。

# ActiveSupport.halt_callback_chains_on_return_false = true

気を取り直してrails s

~/w/threesession [setting-project-restart]× » rails s                                                                                14:57:41
=> Booting WEBrick
=> Rails 5.2.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[2019-07-03 14:57:46] INFO  WEBrick 1.4.2
[2019-07-03 14:57:46] INFO  ruby 2.5.1 (2018-03-29) [x86_64-darwin18]
[2019-07-03 14:57:47] INFO  WEBrick::HTTPServer#start: pid=32275 port=3000

とりあえず!rails sでサーバを立ち上げることができました!

ただ、アプリケーションサーバがWEBrickだったりして、ツッコミどころがあるので、今後rails5のpumaとか、本番環境のunicornを導入しようと思います。

まとめ

今回はここまでですね。phantomjsやら知らないことが出てきました。

過去の自分は理解して導入していたんですかね?

もし理解の上していたらすごいですね。。。

過去の自分に勝てない( ;∀;)

これからは導入背景を理解してから導入し、新しいことはブログやツイッターで発信し、積み上げをしていきます!

今日の変更分はプルリクエストで見れます。

では次回!

SNSでもご購読できます。

スポンサードリンク

コメントを残す

*