質問編集履歴
1
質問を簡潔にした
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ActiveStorage: カスタム previewer
|
1
|
+
ActiveStorage: カスタム previewer を使いたい
|
test
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
### 実現したいこと
|
2
|
+
Ruby On Rails 8 において
|
2
|
-
a
|
3
|
+
ActiveStorage::Previewer を承継した CustomPreviewer を使って previewer として機能させたい。
|
3
|
-
```ruby: custom_previewer.rb
|
4
|
-
class CustomPreviewer < ActiveStorage::Previewer
|
5
|
-
...
|
6
|
-
end
|
7
|
-
```
|
8
|
-
または
|
9
|
-
```ruby: custom_previewer.rb
|
10
|
-
module ActiveStorage
|
11
|
-
module Previewer
|
12
|
-
class CustomePreviewer < Previewer
|
13
|
-
....
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
```
|
18
|
-
config/application.rbにて`config.active_storage.previewers.unshift CustomPreviewer`と記述して
|
19
|
-
image_tag ... previewerとして機能させたい
|
20
4
|
|
21
5
|
|
22
6
|
### 発生している問題・分からないこと
|
23
|
-
起動時に
|
7
|
+
起動時(bin/dev)にエラーが発生する。
|
24
8
|
CustomPreviewer(app/previewers/custom_previewer.rb)が読み込まれてない?か読み込む順番を間違えてしまっているか?
|
25
9
|
|
26
10
|
### エラーメッセージ
|
@@ -36,28 +20,50 @@
|
|
36
20
|
11:22:13 web.1 |
|
37
21
|
11:22:13 web.1 | config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomPreviewer
|
38
22
|
|
39
|
-
|
40
23
|
```
|
41
24
|
|
42
25
|
### 該当のソースコード
|
43
26
|
|
27
|
+
```ruby:app/previewers/custom_previewer.rb
|
28
|
+
class CustomPreviewer < ActiveStorage::Previewer
|
29
|
+
...
|
30
|
+
end
|
44
31
|
```
|
32
|
+
または
|
33
|
+
```ruby:app/previewers/custom_previewer.rb
|
34
|
+
module ActiveStorage
|
35
|
+
module Previewer
|
36
|
+
class CustomePreviewer < Previewer
|
45
|
-
|
37
|
+
....
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
```ruby:config/application.rb
|
43
|
+
module Home
|
44
|
+
class Application < Rails::Application
|
45
|
+
config.load_defaults 8.0
|
46
|
+
...
|
47
|
+
config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomPreviewer
|
48
|
+
または
|
49
|
+
config.active_storage.previewers.unshift CustomPreviewer
|
50
|
+
...
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
または
|
55
|
+
```ruby:config/initializers/active_storage.rbに
|
56
|
+
Rails.application.config.active_storage.previewers.unshift CustomPreviewer
|
57
|
+
Rails.application.config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomePreviewer
|
46
58
|
```
|
47
59
|
|
48
60
|
### 試したこと・調べたこと
|
49
61
|
- [x] teratailやGoogle等で検索した
|
50
62
|
- [x] ソースコードを自分なりに変更した
|
51
63
|
- [ ] 知人に聞いた
|
52
|
-
- [x] その他
|
64
|
+
- [x] その他(ChatGPTに聞いてみた)
|
53
65
|
|
54
66
|
##### 上記の詳細・結果
|
55
|
-
他にconfig/initializers/active_storage.rbに
|
56
|
-
```ruby
|
57
|
-
Rails.application.config.active_storage.previewers.unshift CustomPreviewer
|
58
|
-
Rails.application.config.active_storage.previewers.unshift ActiveStorage::Previewer::CustomePreviewer
|
59
|
-
```
|
60
|
-
も試したが、同じエラーになった
|
61
67
|
|
62
68
|
|
63
69
|
### 補足
|