実現したいこと
Ruby On Rails 8 において
ActiveStorage::Previewer を承継した CustomPreviewer を使って previewer として機能させたい。
発生している問題・分からないこと
起動時(bin/dev)にエラーが発生する。
CustomPreviewer(app/previewers/custom_previewer.rb)が読み込まれてない?か読み込む順番を間違えてしまっているか?
エラーメッセージ
error
1`config.active_storage.previewers.unshift CustomPreviewer`の場合 211:20:59 web.1 | /home/config/application.rb:28:in '<class:Application>': uninitialized constant Home::Application::CustomPreviewer (NameError) 311:20:59 web.1 | 411:20:59 web.1 | config.active_storage.previewers.unshift CustomPreviewer 511:20:59 web.1 | ^^^^^^^^^^^^^^^ 6 7`config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomPreviewer`の場合 811:22:13 web.1 | /home/config/application.rb:28:in '<class:Application>': uninitialized constant ActiveStorage::Previewer::CustomPreviewer (NameError) 911:22:13 web.1 | 1011:22:13 web.1 | config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomPreviewer 11
該当のソースコード
ruby:app/previewers/custom_previewer.rb
1class CustomPreviewer < ActiveStorage::Previewer 2... 3end
または
ruby:app/previewers/custom_previewer.rb
1module ActiveStorage 2 module Previewer 3 class CustomePreviewer < Previewer 4 .... 5 end 6 end 7end
ruby:config/application.rb
1module Home 2 class Application < Rails::Application 3 config.load_defaults 8.0 4 ... 5 config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomPreviewer 6または 7 config.active_storage.previewers.unshift CustomPreviewer 8 ... 9 end 10end
または
ruby:config/initializers/active_storage.rbに
1Rails.application.config.active_storage.previewers.unshift CustomPreviewer 2Rails.application.config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomePreviewer
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他(ChatGPTに聞いてみた)
上記の詳細・結果
補足
特になし

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。