質問編集履歴

2

質問内容の修正

2019/03/25 11:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -123,3 +123,77 @@
123
123
 
124
124
 
125
125
  もうわけがわかりません
126
+
127
+
128
+
129
+
130
+
131
+ ### 追記
132
+
133
+
134
+
135
+ ```
136
+
137
+ class UserImageUploader < ImageUploader
138
+
139
+ # リサイズしたり画像形式を変更するのに必要
140
+
141
+ include CarrierWave::MiniMagick
142
+
143
+
144
+
145
+ process :store_dimensions
146
+
147
+
148
+
149
+ # サイズを半分にしたものを生成してそのサイズを保存する
150
+
151
+ version :half do
152
+
153
+ process :resize
154
+
155
+ end
156
+
157
+
158
+
159
+ def resize
160
+
161
+ Util.log 'resize'
162
+
163
+ resize_to_fit model.resize[0], model.resize[1]
164
+
165
+ end
166
+
167
+
168
+
169
+ def store_dimensions
170
+
171
+ if file && model
172
+
173
+ resize = MiniMagick::Image.open(file.file).dimensions
174
+
175
+ resize[0] = resize[0] / 2
176
+
177
+ resize[1] = resize[1] / 2
178
+
179
+ model.resize = resize
180
+
181
+ end
182
+
183
+ end
184
+
185
+ end
186
+
187
+
188
+
189
+ def url
190
+
191
+ "#{Settings.api.images}#{self.half.current_path}"
192
+
193
+ end
194
+
195
+ ```
196
+
197
+
198
+
199
+ このリサイズしたバージョンのイメージを作らなければ2回呼ばれるだけで正常に保存できるようです

1

質問内容の修正

2019/03/25 11:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -55,3 +55,71 @@
55
55
  そもそも4回呼ばれる理由もわからないのですが
56
56
 
57
57
  Carrierwave はブラックボックスが多すぎて原因が全くわからずどこからデバッグすればいいのでしょうか…
58
+
59
+
60
+
61
+
62
+
63
+ ### 追記
64
+
65
+
66
+
67
+ ```
68
+
69
+ def filename
70
+
71
+ Util.log @f
72
+
73
+ if original_filename
74
+
75
+ @f ||= "#{SecureRandom.hex(5)}#{File.extname(original_filename)}"
76
+
77
+ end
78
+
79
+ Util.log @f
80
+
81
+ @f
82
+
83
+ end
84
+
85
+ ```
86
+
87
+
88
+
89
+ のようにログを増やしてみたのですが
90
+
91
+ 最後の1回だけ @f が nil になってしまいます
92
+
93
+ なので別にインスタンスが作られているとしか思えません…
94
+
95
+
96
+
97
+ ```
98
+
99
+ Util.log caller.select{|r| r.index('/home') == 0}.join("\n")
100
+
101
+ ```
102
+
103
+ トレースをはさんでみたのですが4回とも同じコントローラーの update から呼び出されていました
104
+
105
+
106
+
107
+ コントローラはほとんど手を付けていないデフォルトです
108
+
109
+ もちろんその update が実行されたのは1回だけです
110
+
111
+ ```
112
+
113
+ def update
114
+
115
+ Util.log 'update'
116
+
117
+ respond_to do |format|
118
+
119
+ if @user.update(user_params)
120
+
121
+ ```
122
+
123
+
124
+
125
+ もうわけがわかりません