22
15

More than 5 years have passed since last update.

Rails Aborted! Unknown Verison 5.2と出たら

Last updated at Posted at 2018-08-18

rails newの際にversion指定忘れて作成

ローカルのRails versionが5.2.0の状態で、version指定をせずに、作成したアプリでGemfileをRails Tutorialに沿って書き換えてgit push heroku masterした結果がこちら

Rails Aborted !
Unknown Version 5.2

解決策

bundle exec rails generate not workingを参考に
config/application.rb を開き

config.load_defaults 5.2 #←を5.1に変更

Rails newにてversion指定をしていないと、その後gemfileにてversionを指定しても、configの設定にて5.2を呼びなさいと指定されてる箇所があるので、ここを直す必要がある。

Rails verを指定しなかった過ちは続く

お次に出くわすエラーがこちら

NoMethodError: undefined method `active_storage' for #<Rails::Application::Configuration:0000000000>

Active_storageはrails5.2にて追加された機能。その為、5.1環境に指定し忘れるとこれにまつわるその他諸々の初期設定を全てオフにしなければならない。

一つ目のActive_storage設定オフ

development.rb/production.rbにて

config.active_storage.service = :local

この記述を削除、あるいはコメントアウトする。
そしてgit push heroku masterを実行すると

Sprockets::FileNotFound: couldn't find file 'activestorage' with type 'application/javascript'
remote:        Checked in these paths: 
remote:          /tmp/build_0c6dfb44b8e17ab00878427b9f11286d/app/assets/config
remote:          /tmp/build_0c6dfb44b8e17ab00878427b9f11286d/app/assets/images
remote:          /tmp/build_0c6dfb44b8e17ab00878427b9f11286d/app/assets/javascripts

なんとassetsにまで残骸がある模様
application.jsファイルにある

//=require active_storage

これを削除
加えてconfig/storage.ymlのファイルをstorage.ymlごと削除

これで無事に git push heroku masterは通るようになる。
githubでは問題なく通ってしまう為、盲点かもしれない。

これで解決したわけではない

早速アプリの内容を改変して、サーバーを立ち上げようと立ち上げると

app error: Missing secret_token and secret_key_base for development' environment, set these values in config/secrets.yml (RuntimeError)

rails s が失敗してERROR RuntimeError: Missing secret_key_base と言われました。こちらの記事を参考に
config/secrets.ymlを作成して
bundle exec rake secretにて作成したkeyを

development:
  secret_key_base: 1232313213213213131231231231231231

以下のように貼り付けることで解決。
かに思われた。
rails sを再度実行すると

oMethodError in Rails::WelcomeController#index
undefined method `verbose_query_logs=' for ActiveRecord::Base:Class

が出現。
ググってもこのようなエラーは類がなく、しかしActiveRecordまた貴様に関するエラーか・・!

解決策

ググり方を変え、そもそもこのメソッドverbose_query_logsは何なのかを検索。
Rails 5.2新機能を先行チェック!Active Storage/ダイレクトアップロード/Early Hintsほか(翻訳)にて該当部分を発見。
config/environment/development.rbにて

 # Highlight code that triggered database queries in logs.
  config.active_record.verbose_query_logs = true #これをfalseに変更

こんなところにもまだ設定が残っていたのかと・・falseに変更することで無事にrails sでページが表示された。

結論

最初にversion指定を忘れて作った段階で、作成したアプリをその場で削除して一から作り直す方が良い

追記

rails testを実行すると


/Users/Watashida/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `active_storage' for #<Rails::Application::Configuration:0x00007fda90ddfd48> (NoMethodError)
    from /Users/Watashida/environment/sample_app/config/environments/test.rb:32:in `block in <main>'

まだ残っていた

config/environments/test.rbにて

# Store uploaded files on the local file system in a temporary directory
   config.active_storage.service = :test #これをコメントアウト

最後のactive_storage設定をコメントアウト。

改めてrails testを実行すると

# Running:

Run options: --seed 43459

# Running:



Finished in 0.001305s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips



Finished in 0.227700s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips

エラー無し。

22
15
0

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
22
15