LoginSignup
0
0

More than 1 year has passed since last update.

Rails6.0から6.1へアップデートしたらActive Strageでエラーが出た。

Last updated at Posted at 2021-06-29

Railsのバージョンを6.0から6.1へとアップデートした際に、Active Strageで以下のようなエラーが出ました。

エラー文

ArgumentError - Can't resolve image into URL: undefined method `service_name' for #ActiveStorage::Blob:0x00007f9cf0bd9810

エラー画面

スクリーンショット 2021-06-29 14.31.17.jpg

このエラーに対する情報がなかったので、本記事で解決法を書いてみました。

エラーの原因

Railsをアップデートしたことにより、Active Strageもアップデートしないといけないです。

解決方法

ターミナルに以下を入力し、アップデート用のマイグレーションを作成する必要があります。

% rails active_storage:update

# 実行結果
Copied migration 20210629053156_add_service_name_to_active_storage_blobs.active_storage.rb from active_storage
Copied migration 20210629053157_create_active_storage_variant_records.active_storage.rb from active_storage

すると、アップデート用のマイグレーションファイルが2つ作成されているので、こちらをmaigrateしてあげましょう。

まず、statusコマンドで作成されていることを確認します。

% rails db:migrate:status

# 実行結果
database: 〇〇_development

 Status   Migration ID    Migration Name
--------------------------------------------------
  down    20210629053156  Add service name to active storage blobsactive storage
  down    20210629053157  Create active storage variant recordsactive storage

確認ができたら、maigrateを実行しましょう。

% rails db:migrate 

statusコマンドで再度確認。

% rails db:migrate:status

database: 〇〇_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20210629053156  Add service name to active storage blobsactive storage
   up     20210629053157  Create active storage variant recordsactive storage

statusがupになってますね。
これで解決です!

同じ状況で困っている方の参考になれば嬉しいです!

0
0
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
0
0