質問編集履歴
12
追記、エラー発生
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,186 +44,306 @@
|
|
44
44
|
|
45
45
|
➡︎このコードだとエラーが発生<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
46
46
|
|
47
|
+
|
48
|
+
|
49
|
+
➡︎このコードだとエラーが発生(NoMethodError in Users#show)<div class="content_post" style="background-image: url(<%= url_for(item.image.url)=%>
|
50
|
+
|
51
|
+
<div class="more">
|
52
|
+
|
53
|
+
<span><%= image_tag 'arrow_top.png'%></span>
|
54
|
+
|
55
|
+
<ul class="more_list">
|
56
|
+
|
57
|
+
<li>
|
58
|
+
|
59
|
+
<%= link_to '詳細', item_path(item.id), method: :get%>
|
60
|
+
|
61
|
+
</li>
|
62
|
+
|
63
|
+
<% if user_signed_in? && current_user.id == item.user_id %>
|
64
|
+
|
65
|
+
<li>
|
66
|
+
|
67
|
+
<%= link_to '削除', item_path(item.id), method: :delete %>
|
68
|
+
|
69
|
+
</li>
|
70
|
+
|
71
|
+
<%# Prefixの引数 %>
|
72
|
+
|
73
|
+
<%# アイテムのID(item.id) %>
|
74
|
+
|
75
|
+
<%# HTTPメソッドは、DELETEというHTTPメソッド %>
|
76
|
+
|
77
|
+
<%# methodオプションにシンボルで:delete %>
|
78
|
+
|
79
|
+
<li>
|
80
|
+
|
81
|
+
<%= link_to '編集',edit_item_path(item.id), method: :get %>
|
82
|
+
|
83
|
+
<%# get サーバーからブラウザに情報を返す。単にウェブサイトを閲覧する際など、情報を取得するために利用される。 %>
|
84
|
+
|
85
|
+
<%# Prefixでパスを確認 %>
|
86
|
+
|
87
|
+
</li>
|
88
|
+
|
89
|
+
<% end %>
|
90
|
+
|
91
|
+
</ul>
|
92
|
+
|
93
|
+
</div>
|
94
|
+
|
95
|
+
<p><%= item.text %></p>
|
96
|
+
|
97
|
+
<span class="name">
|
98
|
+
|
99
|
+
<a href="/users/<%= item.user.id %>">
|
100
|
+
|
101
|
+
<span>投稿者</span><%= item.user.nickname %>
|
102
|
+
|
103
|
+
</a>
|
104
|
+
|
105
|
+
</span>
|
106
|
+
|
107
|
+
</div>
|
108
|
+
|
109
|
+
>
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
➡︎エラー内容
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
NoMethodError in Users#show
|
122
|
+
|
123
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fc948e1ff28>
|
128
|
+
|
129
|
+
Extracted source (around line #1):
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
<div class="content_post" style="background-image: url(<%= url_for(item.image.url)=%>
|
134
|
+
|
135
|
+
<%= image_tag item.image.variant(resize: '500x500'), class: 'item-image' if item.image.attached? %>
|
136
|
+
|
137
|
+
<%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
Trace of template inclusion: #<ActionView::Template app/views/users/show.html.erb locals=[]>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
Application Trace | Framework Trace | Full Trace
|
150
|
+
|
151
|
+
app/views/items/_item.html.erb:1
|
152
|
+
|
153
|
+
app/views/users/show.html.erb:4
|
154
|
+
|
155
|
+
app/views/users/show.html.erb:3
|
156
|
+
|
157
|
+
Request
|
158
|
+
|
159
|
+
Parameters:
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
https://gyazo.com/17411c4b60fe029ecbe7f89f2b7156e2
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
### 試したこと
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
app/veiws/veiws/_item.html.erb
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
<code>
|
176
|
+
|
177
|
+
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
178
|
+
|
179
|
+
画像が表示されず、エラーなし
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
➡︎1パターン目image_urlを使った場合
|
188
|
+
|
189
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
190
|
+
|
191
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
The asset "" is not present in the asset pipeline.
|
196
|
+
|
197
|
+
Extracted source (around line #1):
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
202
|
+
|
203
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
204
|
+
|
47
205
|
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
48
206
|
|
49
207
|
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
50
208
|
|
51
|
-
|
52
|
-
|
53
|
-
<
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
</li>
|
90
|
-
|
91
|
-
<% end %>
|
92
|
-
|
93
|
-
</ul>
|
94
|
-
|
95
|
-
</div>
|
96
|
-
|
97
|
-
<p><%= item.text %></p>
|
98
|
-
|
99
|
-
<span class="name">
|
100
|
-
|
101
|
-
<a href="/users/<%= item.user.id %>">
|
102
|
-
|
103
|
-
<span>投稿者</span><%= item.user.nickname %>
|
104
|
-
|
105
|
-
</a>
|
106
|
-
|
107
|
-
</span>
|
108
|
-
|
109
|
-
</div>
|
110
|
-
|
111
|
-
>
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
```
|
116
|
-
|
117
|
-
➡︎エラー内容
|
118
|
-
|
119
|
-
```
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
NoMethodError in Users#show
|
124
|
-
|
125
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fc948e1ff28>
|
130
|
-
|
131
|
-
Extracted source (around line #1):
|
132
|
-
|
133
|
-
|
209
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
210
|
+
|
211
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
Application Trace | Framework Trace | Full Trace
|
224
|
+
|
225
|
+
app/views/items/_item.html.erb:1
|
226
|
+
|
227
|
+
app/views/items/index.html.erb:7
|
228
|
+
|
229
|
+
app/views/items/index.html.erb:6:in `each'
|
230
|
+
|
231
|
+
app/views/items/index.html.erb:6
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
➡︎2パターン目image_pathを使った場合
|
236
|
+
|
237
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
238
|
+
|
239
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
The asset "" is not present in the asset pipeline.
|
244
|
+
|
245
|
+
Extracted source (around line #1):
|
134
246
|
|
135
247
|
|
136
248
|
|
249
|
+
|
250
|
+
|
137
|
-
<div class="content_post" style="background-image: url(<%=
|
251
|
+
<div class="content_post" style="background-image: url(<%= image_path item.image %>) ;">
|
252
|
+
|
138
|
-
|
253
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
Application Trace | Framework Trace | Full Trace
|
268
|
+
|
269
|
+
app/views/items/_item.html.erb:1
|
270
|
+
|
271
|
+
app/views/items/index.html.erb:7
|
272
|
+
|
273
|
+
app/views/items/index.html.erb:6:in `each'
|
274
|
+
|
275
|
+
app/views/items/index.html.erb:6
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
➡︎3パターン目をitem.image.path使った場合
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
NoMethodError in Items#index
|
284
|
+
|
285
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
undefined method `path' for #<ActiveStorage::Attached::One:0x00007fee7e66ff70>
|
290
|
+
|
291
|
+
Extracted source (around line #1):
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
<div class="content_post" style="background-image: url(<%= item.image.path %>) ;">
|
296
|
+
|
297
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
298
|
+
|
139
|
-
<%= image_tag item.image
|
299
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
140
|
-
|
300
|
+
|
141
|
-
<%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
301
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
142
302
|
|
143
303
|
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
144
304
|
|
145
305
|
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
146
306
|
|
147
|
-
|
307
|
+
|
148
|
-
|
149
|
-
|
150
|
-
|
308
|
+
|
151
|
-
Trace of template inclusion: #<ActionView::Template app/views/
|
309
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
152
|
-
|
153
|
-
|
154
|
-
|
310
|
+
|
311
|
+
|
312
|
+
|
155
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
313
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
156
|
-
|
157
|
-
|
158
|
-
|
314
|
+
|
315
|
+
|
316
|
+
|
159
|
-
Application Trace | Framework Trace | Full Trace
|
317
|
+
Application Trace | Framework Trace | Full Trace
|
160
|
-
|
318
|
+
|
161
|
-
app/views/items/_item.html.erb:1
|
319
|
+
app/views/items/_item.html.erb:1
|
162
|
-
|
320
|
+
|
163
|
-
app/views/
|
321
|
+
app/views/items/index.html.erb:7
|
322
|
+
|
164
|
-
|
323
|
+
app/views/items/index.html.erb:6:in `each'
|
324
|
+
|
165
|
-
app/views/
|
325
|
+
app/views/items/index.html.erb:6
|
166
|
-
|
167
|
-
|
326
|
+
|
168
|
-
|
169
|
-
|
327
|
+
|
170
|
-
|
171
|
-
|
328
|
+
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
https://gyazo.com/17411c4b60fe029ecbe7f89f2b7156e2
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
### 試したこと
|
182
|
-
|
183
|
-
```
|
184
|
-
|
185
|
-
app/veiws/veiws/_item.html.erb
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
<code>
|
190
|
-
|
191
|
-
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
192
|
-
|
193
|
-
画像が表示されず、エラーなし
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
➡︎
|
329
|
+
➡︎4パターン目をitem.image.url使った場合
|
202
|
-
|
330
|
+
|
203
|
-
|
331
|
+
NoMethodError in Items#index
|
204
|
-
|
332
|
+
|
205
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
333
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
206
|
-
|
207
|
-
|
208
|
-
|
334
|
+
|
335
|
+
|
336
|
+
|
209
|
-
|
337
|
+
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fee7f6197c8>
|
210
338
|
|
211
339
|
Extracted source (around line #1):
|
212
340
|
|
213
341
|
|
214
342
|
|
215
|
-
<div class="content_post" style="background-image: url(<%= i
|
343
|
+
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
216
344
|
|
217
345
|
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
218
346
|
|
219
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
220
|
-
|
221
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
222
|
-
|
223
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
224
|
-
|
225
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
226
|
-
|
227
347
|
|
228
348
|
|
229
349
|
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
@@ -246,36 +366,26 @@
|
|
246
366
|
|
247
367
|
|
248
368
|
|
249
|
-
|
250
|
-
|
251
|
-
➡︎
|
369
|
+
➡︎5パターン目@item.image.urlを使った場合
|
252
|
-
|
370
|
+
|
371
|
+
|
372
|
+
|
253
|
-
|
373
|
+
NoMethodError in Items#index
|
254
|
-
|
374
|
+
|
255
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
375
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
256
|
-
|
257
|
-
|
258
|
-
|
376
|
+
|
377
|
+
|
378
|
+
|
259
|
-
|
379
|
+
undefined method `image' for nil:NilClass
|
260
|
-
|
380
|
+
|
261
|
-
Extracted source (around line #1):
|
381
|
+
Extracted source (around line #1):
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
382
|
+
|
383
|
+
|
384
|
+
|
267
|
-
<div class="content_post" style="background-image: url(<%= image_
|
385
|
+
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
268
386
|
|
269
387
|
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
270
388
|
|
271
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
272
|
-
|
273
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
274
|
-
|
275
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
276
|
-
|
277
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
278
|
-
|
279
389
|
|
280
390
|
|
281
391
|
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
@@ -298,135 +408,19 @@
|
|
298
408
|
|
299
409
|
|
300
410
|
|
301
|
-
➡︎3パターン目をitem.image.path使った場合
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
NoMethodError in Items#index
|
306
|
-
|
307
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
undefined method `path' for #<ActiveStorage::Attached::One:0x00007fee7e66ff70>
|
312
|
-
|
313
|
-
Extracted source (around line #1):
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
<div class="content_post" style="background-image: url(<%= item.image.path %>) ;">
|
318
|
-
|
319
|
-
|
411
|
+
➡︎6パターン目<div class="content_post" style="background-image: url(<%= url_for(item.image) ,class: 'item-image' if item.image.attached? %>
|
320
|
-
|
321
|
-
|
412
|
+
|
322
|
-
|
323
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
324
|
-
|
325
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
326
|
-
|
327
|
-
|
413
|
+
上記のコードでエラーが発生しました。
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
414
|
+
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
415
|
+
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
416
|
+
|
340
|
-
|
341
|
-
|
417
|
+
エラースクリーンショット
|
342
|
-
|
343
|
-
|
418
|
+
|
344
|
-
|
345
|
-
|
419
|
+
https://gyazo.com/f1fe843012299d2dc4ec19060bf82905
|
346
|
-
|
347
|
-
|
420
|
+
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
421
|
+
続き
|
352
|
-
|
353
|
-
|
422
|
+
|
354
|
-
|
355
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fee7f6197c8>
|
360
|
-
|
361
|
-
Extracted source (around line #1):
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
366
|
-
|
367
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
Application Trace | Framework Trace | Full Trace
|
380
|
-
|
381
|
-
app/views/items/_item.html.erb:1
|
382
|
-
|
383
|
-
app/views/items/index.html.erb:7
|
384
|
-
|
385
|
-
|
423
|
+
https://gyazo.com/e89d008392120fa0a804ff47f8a90bf3
|
386
|
-
|
387
|
-
app/views/items/index.html.erb:6
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
➡︎5パターン目@item.image.urlを使った場合
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
NoMethodError in Items#index
|
396
|
-
|
397
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
undefined method `image' for nil:NilClass
|
402
|
-
|
403
|
-
Extracted source (around line #1):
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
408
|
-
|
409
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
Application Trace | Framework Trace | Full Trace
|
422
|
-
|
423
|
-
app/views/items/_item.html.erb:1
|
424
|
-
|
425
|
-
app/views/items/index.html.erb:7
|
426
|
-
|
427
|
-
app/views/items/index.html.erb:6:in `each'
|
428
|
-
|
429
|
-
app/views/items/index.html.erb:6
|
430
424
|
|
431
425
|
|
432
426
|
|
@@ -464,9 +458,27 @@
|
|
464
458
|
|
465
459
|
bucket: 自身のバケット名
|
466
460
|
|
461
|
+
|
462
|
+
|
463
|
+
環境設定
|
464
|
+
|
465
|
+
config/enviloment/developments.rb
|
466
|
+
|
467
|
+
最後の記述
|
468
|
+
|
469
|
+
# default_url_options[:host] = "localhost:3000"
|
470
|
+
|
471
|
+
host = 'samplehost'
|
472
|
+
|
473
|
+
Rails.application.routes.default_url_options[:host] = host
|
474
|
+
|
475
|
+
#おそらく本番環境productionにも定義
|
476
|
+
|
477
|
+
ここを記載してlocalでは表示させることが出来ました。
|
478
|
+
|
479
|
+
url_forメソッドを使用して
|
480
|
+
|
467
|
-
```
|
481
|
+
```
|
468
|
-
|
469
|
-
|
470
482
|
|
471
483
|
追記11/6 20:42
|
472
484
|
|
11
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
投稿した画像をimage_tag もしくはurl_forを使って背景に表示させたい。
|
test
CHANGED
File without changes
|
10
修正後のコードとエラー
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
Ruby on railsで画像が投稿できるようなシステムを作っています。
|
8
|
-
|
4
|
+
|
9
|
-
画像を表示させたい。
|
5
|
+
画像を背景に表示させたい。
|
10
6
|
|
11
7
|
|
12
8
|
|
@@ -14,17 +10,19 @@
|
|
14
10
|
|
15
11
|
|
16
12
|
|
17
|
-
|
13
|
+
active storageに投稿した画像を保存し表示できるように出来ました。
|
18
|
-
|
14
|
+
|
19
|
-
|
15
|
+
その後、AWSのS3に投稿して画像を保存して表示させようとすると、エラーが発生し、
|
20
16
|
|
21
17
|
HTMLの記述を修正しました。
|
22
18
|
|
23
19
|
|
24
20
|
|
25
|
-
画像データが正常に送られているのがわかるのですが、
|
21
|
+
画像データがレコードには正常に送られているのがわかるのですが、
|
26
|
-
|
22
|
+
|
27
|
-
画像が表示されず
|
23
|
+
画像が表示されず困っています。
|
24
|
+
|
25
|
+
_item.html.erbの画像を表示させるコードに問題があると思います。
|
28
26
|
|
29
27
|
|
30
28
|
|
@@ -44,13 +42,13 @@
|
|
44
42
|
|
45
43
|
➡︎このコードだと画像が表示されない<div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
46
44
|
|
47
|
-
➡︎このコードだとエラーが発生<%# <div class="content_post" style="background-image: url(<%= Rails.ap
|
45
|
+
➡︎このコードだとエラーが発生<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
48
46
|
|
49
47
|
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
50
48
|
|
51
49
|
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
52
50
|
|
53
|
-
|
51
|
+
➡︎このコードだとエラーが発生(NoMethodError in Users#show)<div class="content_post" style="background-image: url(<%= url_for(item.image.url)=%>
|
54
52
|
|
55
53
|
<div class="more">
|
56
54
|
|
@@ -114,49 +112,143 @@
|
|
114
112
|
|
115
113
|
|
116
114
|
|
115
|
+
```
|
116
|
+
|
117
117
|
➡︎エラー内容
|
118
118
|
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
119
|
-
|
123
|
+
NoMethodError in Users#show
|
124
|
+
|
120
|
-
|
125
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fc948e1ff28>
|
130
|
+
|
121
|
-
Extracted source (around line #
|
131
|
+
Extracted source (around line #1):
|
132
|
+
|
133
|
+
|
122
134
|
|
123
135
|
|
124
136
|
|
137
|
+
<div class="content_post" style="background-image: url(<%= url_for(item.image.url)=%>
|
138
|
+
|
139
|
+
<%= image_tag item.image.variant(resize: '500x500'), class: 'item-image' if item.image.attached? %>
|
140
|
+
|
141
|
+
<%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
142
|
+
|
143
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
144
|
+
|
145
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
146
|
+
|
147
|
+
<%# image_tagメソッドでは、複雑なRailsのディレクトリパスを指定しなくても、モデルから画像ファイルを呼び出して引数に記述するだけで、画像を表示するimg要素を生成 %>
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
Trace of template inclusion: #<ActionView::Template app/views/users/show.html.erb locals=[]>
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
Application Trace | Framework Trace | Full Trace
|
160
|
+
|
161
|
+
app/views/items/_item.html.erb:1
|
162
|
+
|
163
|
+
app/views/users/show.html.erb:4
|
164
|
+
|
165
|
+
app/views/users/show.html.erb:3
|
166
|
+
|
167
|
+
Request
|
168
|
+
|
169
|
+
Parameters:
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
https://gyazo.com/17411c4b60fe029ecbe7f89f2b7156e2
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
### 試したこと
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
app/veiws/veiws/_item.html.erb
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
<code>
|
190
|
+
|
191
|
+
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
192
|
+
|
193
|
+
画像が表示されず、エラーなし
|
194
|
+
|
195
|
+
|
196
|
+
|
125
|
-
<
|
197
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
198
|
+
|
199
|
+
|
200
|
+
|
126
|
-
|
201
|
+
➡︎1パターン目image_urlを使った場合
|
202
|
+
|
203
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
204
|
+
|
205
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
The asset "" is not present in the asset pipeline.
|
210
|
+
|
211
|
+
Extracted source (around line #1):
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
216
|
+
|
127
|
-
<div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached?
|
217
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
128
218
|
|
129
219
|
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
130
220
|
|
131
|
-
|
221
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
132
|
-
|
133
|
-
|
134
|
-
|
222
|
+
|
135
|
-
|
223
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
136
|
-
|
137
|
-
|
138
|
-
|
224
|
+
|
139
|
-
#
|
225
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
226
|
+
|
227
|
+
|
228
|
+
|
140
|
-
|
229
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
234
|
+
|
235
|
+
|
236
|
+
|
141
|
-
|
237
|
+
Application Trace | Framework Trace | Full Trace
|
142
|
-
|
238
|
+
|
143
|
-
app/ve
|
239
|
+
app/views/items/_item.html.erb:1
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
240
|
+
|
148
|
-
|
149
|
-
|
241
|
+
app/views/items/index.html.erb:7
|
150
|
-
|
151
|
-
|
242
|
+
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
243
|
+
app/views/items/index.html.erb:6:in `each'
|
244
|
+
|
156
|
-
|
245
|
+
app/views/items/index.html.erb:6
|
157
|
-
|
158
|
-
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
159
|
-
➡︎
|
251
|
+
➡︎2パターン目image_pathを使った場合
|
160
252
|
|
161
253
|
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
162
254
|
|
@@ -170,7 +262,9 @@
|
|
170
262
|
|
171
263
|
|
172
264
|
|
265
|
+
|
266
|
+
|
173
|
-
<div class="content_post" style="background-image: url(<%= image_
|
267
|
+
<div class="content_post" style="background-image: url(<%= image_path item.image %>) ;">
|
174
268
|
|
175
269
|
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
176
270
|
|
@@ -204,25 +298,23 @@
|
|
204
298
|
|
205
299
|
|
206
300
|
|
207
|
-
|
208
|
-
|
209
|
-
➡︎
|
301
|
+
➡︎3パターン目をitem.image.path使った場合
|
210
|
-
|
302
|
+
|
303
|
+
|
304
|
+
|
211
|
-
|
305
|
+
NoMethodError in Items#index
|
212
|
-
|
306
|
+
|
213
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
307
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
214
|
-
|
215
|
-
|
216
|
-
|
308
|
+
|
309
|
+
|
310
|
+
|
217
|
-
|
311
|
+
undefined method `path' for #<ActiveStorage::Attached::One:0x00007fee7e66ff70>
|
218
312
|
|
219
313
|
Extracted source (around line #1):
|
220
314
|
|
221
315
|
|
222
316
|
|
223
|
-
|
224
|
-
|
225
|
-
<div class="content_post" style="background-image: url(<%= i
|
317
|
+
<div class="content_post" style="background-image: url(<%= item.image.path %>) ;">
|
226
318
|
|
227
319
|
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
228
320
|
|
@@ -256,9 +348,7 @@
|
|
256
348
|
|
257
349
|
|
258
350
|
|
259
|
-
➡︎
|
351
|
+
➡︎4パターン目をitem.image.url使った場合
|
260
|
-
|
261
|
-
|
262
352
|
|
263
353
|
NoMethodError in Items#index
|
264
354
|
|
@@ -266,24 +356,16 @@
|
|
266
356
|
|
267
357
|
|
268
358
|
|
269
|
-
undefined method `
|
359
|
+
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fee7f6197c8>
|
270
360
|
|
271
361
|
Extracted source (around line #1):
|
272
362
|
|
273
363
|
|
274
364
|
|
275
|
-
<div class="content_post" style="background-image: url(<%= item.image.
|
365
|
+
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
276
366
|
|
277
367
|
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
278
368
|
|
279
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
280
|
-
|
281
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
282
|
-
|
283
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
284
|
-
|
285
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
286
|
-
|
287
369
|
|
288
370
|
|
289
371
|
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
@@ -306,7 +388,9 @@
|
|
306
388
|
|
307
389
|
|
308
390
|
|
309
|
-
➡︎
|
391
|
+
➡︎5パターン目@item.image.urlを使った場合
|
392
|
+
|
393
|
+
|
310
394
|
|
311
395
|
NoMethodError in Items#index
|
312
396
|
|
@@ -314,24 +398,16 @@
|
|
314
398
|
|
315
399
|
|
316
400
|
|
317
|
-
undefined method `
|
401
|
+
undefined method `image' for nil:NilClass
|
318
|
-
|
402
|
+
|
319
|
-
Extracted source (around line #1):
|
403
|
+
Extracted source (around line #1):
|
320
|
-
|
321
|
-
|
322
|
-
|
404
|
+
|
405
|
+
|
406
|
+
|
323
|
-
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
407
|
+
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
324
408
|
|
325
409
|
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
326
410
|
|
327
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
328
|
-
|
329
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
330
|
-
|
331
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
332
|
-
|
333
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
334
|
-
|
335
411
|
|
336
412
|
|
337
413
|
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
@@ -354,59 +430,7 @@
|
|
354
430
|
|
355
431
|
|
356
432
|
|
357
|
-
➡︎5パターン目@item.image.urlを使った場合
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
NoMethodError in Items#index
|
362
|
-
|
363
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
undefined method `image' for nil:NilClass
|
368
|
-
|
369
|
-
Extracted source (around line #1):
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
374
|
-
|
375
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
376
|
-
|
377
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
378
|
-
|
379
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
380
|
-
|
381
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
382
|
-
|
383
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
Application Trace | Framework Trace | Full Trace
|
396
|
-
|
397
|
-
app/views/items/_item.html.erb:1
|
398
|
-
|
399
|
-
app/views/items/index.html.erb:7
|
400
|
-
|
401
|
-
app/views/items/index.html.erb:6:in `each'
|
402
|
-
|
403
|
-
app/views/items/index.html.erb:6
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
```
|
433
|
+
```
|
408
|
-
|
409
|
-
|
410
434
|
|
411
435
|
補足
|
412
436
|
|
9
質問の回答を編集して記載しました!
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
(例)Ruby on railsで画像が投稿できるようなシステムを作っています。
|
8
8
|
|
@@ -14,35 +14,131 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
まずactive storageに投稿した画像を保存し表示できるように出来ました。
|
18
|
+
|
19
|
+
次にAWSのS3に投稿して画像を保存して表示させようとすると、エラーが発生し、
|
20
|
+
|
21
|
+
HTMLの記述を修正しました。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
画像データが正常に送られているのがわかるのですが、
|
26
|
+
|
27
|
+
画像が表示されず、困っています。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
### 該当のソースコード
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```Ruby on rails
|
36
|
+
|
37
|
+
app/veiws/veiws/_item.html.erb
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
<code>
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
➡︎このコードだと画像が表示されない<div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
46
|
+
|
47
|
+
➡︎このコードだとエラーが発生<%# <div class="content_post" style="background-image: url(<%= Rails.apコーフ度plication.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
48
|
+
|
49
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
50
|
+
|
51
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
<div class="more">
|
56
|
+
|
57
|
+
<span><%= image_tag 'arrow_top.png'%></span>
|
58
|
+
|
59
|
+
<ul class="more_list">
|
60
|
+
|
61
|
+
<li>
|
62
|
+
|
63
|
+
<%= link_to '詳細', item_path(item.id), method: :get%>
|
64
|
+
|
65
|
+
</li>
|
66
|
+
|
67
|
+
<% if user_signed_in? && current_user.id == item.user_id %>
|
68
|
+
|
69
|
+
<li>
|
70
|
+
|
71
|
+
<%= link_to '削除', item_path(item.id), method: :delete %>
|
72
|
+
|
73
|
+
</li>
|
74
|
+
|
75
|
+
<%# Prefixの引数 %>
|
76
|
+
|
77
|
+
<%# アイテムのID(item.id) %>
|
78
|
+
|
79
|
+
<%# HTTPメソッドは、DELETEというHTTPメソッド %>
|
80
|
+
|
81
|
+
<%# methodオプションにシンボルで:delete %>
|
82
|
+
|
83
|
+
<li>
|
84
|
+
|
85
|
+
<%= link_to '編集',edit_item_path(item.id), method: :get %>
|
86
|
+
|
87
|
+
<%# get サーバーからブラウザに情報を返す。単にウェブサイトを閲覧する際など、情報を取得するために利用される。 %>
|
88
|
+
|
89
|
+
<%# Prefixでパスを確認 %>
|
90
|
+
|
91
|
+
</li>
|
92
|
+
|
93
|
+
<% end %>
|
94
|
+
|
95
|
+
</ul>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<p><%= item.text %></p>
|
100
|
+
|
101
|
+
<span class="name">
|
102
|
+
|
103
|
+
<a href="/users/<%= item.user.id %>">
|
104
|
+
|
105
|
+
<span>投稿者</span><%= item.user.nickname %>
|
106
|
+
|
107
|
+
</a>
|
108
|
+
|
109
|
+
</span>
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
>
|
114
|
+
|
115
|
+
|
116
|
+
|
17
|
-
エラー
|
117
|
+
➡︎エラー内容
|
18
118
|
|
19
119
|
ActionView::SyntaxErrorInTemplate in ItemsController#index
|
20
120
|
|
21
|
-
|
22
|
-
|
23
|
-
|
121
|
+
Extracted source (around line #3):
|
122
|
+
|
123
|
+
|
124
|
+
|
24
|
-
|
125
|
+
<%# <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;"> %>
|
126
|
+
|
127
|
+
<div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached?
|
128
|
+
|
25
|
-
|
129
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
26
|
-
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
27
|
-
|
135
|
+
```
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
136
|
+
|
32
|
-
|
33
|
-
|
137
|
+
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
138
|
+
|
41
|
-
###
|
139
|
+
### 試したこと
|
42
|
-
|
43
|
-
|
44
|
-
|
140
|
+
|
45
|
-
```
|
141
|
+
```
|
46
142
|
|
47
143
|
app/veiws/veiws/_item.html.erb
|
48
144
|
|
@@ -50,11 +146,33 @@
|
|
50
146
|
|
51
147
|
<code>
|
52
148
|
|
53
|
-
|
54
|
-
|
55
|
-
|
149
|
+
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
150
|
+
|
56
|
-
|
151
|
+
画像が表示されず、エラーなし
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
➡︎1パターン目image_urlを使った場合
|
160
|
+
|
161
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
162
|
+
|
163
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
The asset "" is not present in the asset pipeline.
|
168
|
+
|
169
|
+
Extracted source (around line #1):
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
174
|
+
|
57
|
-
|
175
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
58
176
|
|
59
177
|
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
60
178
|
|
@@ -64,89 +182,225 @@
|
|
64
182
|
|
65
183
|
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
66
184
|
|
67
|
-
|
185
|
+
|
68
|
-
|
69
|
-
|
186
|
+
|
70
|
-
|
71
|
-
|
187
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
72
|
-
|
73
|
-
|
188
|
+
|
74
|
-
|
75
|
-
|
189
|
+
|
76
|
-
|
77
|
-
|
190
|
+
|
78
|
-
|
79
|
-
</li>
|
80
|
-
|
81
|
-
<% if user_signed_in? && current_user.id == item.user_id %>
|
82
|
-
|
83
|
-
<li>
|
84
|
-
|
85
|
-
<%= link_to '削除', item_path(item.id), method: :delete %>
|
86
|
-
|
87
|
-
</li>
|
88
|
-
|
89
|
-
<%# Prefixの引数 %>
|
90
|
-
|
91
|
-
<%# アイテムのID(item.id) %>
|
92
|
-
|
93
|
-
<%# HTTPメソッドは、DELETEというHTTPメソッド %>
|
94
|
-
|
95
|
-
<%# methodオプションにシンボルで:delete %>
|
96
|
-
|
97
|
-
<li>
|
98
|
-
|
99
|
-
<%= link_to '編集',edit_item_path(item.id), method: :get %>
|
100
|
-
|
101
|
-
<%# get サーバーからブラウザに情報を返す。単にウェブサイトを閲覧する際など、情報を取得するために利用される。 %>
|
102
|
-
|
103
|
-
<%# Prefixでパスを確認 %>
|
104
|
-
|
105
|
-
</li>
|
106
|
-
|
107
|
-
<% end %>
|
108
|
-
|
109
|
-
</ul>
|
110
|
-
|
111
|
-
</div>
|
112
|
-
|
113
|
-
<p><%= item.text %></p>
|
114
|
-
|
115
|
-
<span class="name">
|
116
|
-
|
117
|
-
|
191
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
192
|
+
|
193
|
+
|
194
|
+
|
118
|
-
|
195
|
+
Application Trace | Framework Trace | Full Trace
|
196
|
+
|
197
|
+
app/views/items/_item.html.erb:1
|
198
|
+
|
199
|
+
app/views/items/index.html.erb:7
|
200
|
+
|
119
|
-
|
201
|
+
app/views/items/index.html.erb:6:in `each'
|
120
|
-
|
202
|
+
|
121
|
-
|
203
|
+
app/views/items/index.html.erb:6
|
122
|
-
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
123
|
-
|
209
|
+
➡︎2パターン目image_pathを使った場合
|
124
|
-
|
125
|
-
|
210
|
+
|
126
|
-
|
127
|
-
>
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
➡︎エラー内容
|
132
|
-
|
133
|
-
|
211
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
212
|
+
|
134
|
-
|
213
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
The asset "" is not present in the asset pipeline.
|
218
|
+
|
135
|
-
Extracted source (around line #
|
219
|
+
Extracted source (around line #1):
|
136
220
|
|
137
221
|
|
138
222
|
|
223
|
+
|
224
|
+
|
139
|
-
<
|
225
|
+
<div class="content_post" style="background-image: url(<%= image_path item.image %>) ;">
|
140
|
-
|
226
|
+
|
141
|
-
<div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached?
|
227
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
142
|
-
|
228
|
+
|
143
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
229
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
230
|
+
|
144
|
-
|
231
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
232
|
+
|
145
|
-
|
233
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
234
|
+
|
146
|
-
|
235
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
236
|
+
|
237
|
+
|
238
|
+
|
147
|
-
|
239
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
240
|
+
|
241
|
+
|
242
|
+
|
148
|
-
|
243
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
244
|
+
|
245
|
+
|
246
|
+
|
149
|
-
|
247
|
+
Application Trace | Framework Trace | Full Trace
|
248
|
+
|
249
|
+
app/views/items/_item.html.erb:1
|
250
|
+
|
251
|
+
app/views/items/index.html.erb:7
|
252
|
+
|
253
|
+
app/views/items/index.html.erb:6:in `each'
|
254
|
+
|
255
|
+
app/views/items/index.html.erb:6
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
➡︎3パターン目をitem.image.path使った場合
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
NoMethodError in Items#index
|
264
|
+
|
265
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
undefined method `path' for #<ActiveStorage::Attached::One:0x00007fee7e66ff70>
|
270
|
+
|
271
|
+
Extracted source (around line #1):
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
<div class="content_post" style="background-image: url(<%= item.image.path %>) ;">
|
276
|
+
|
277
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
278
|
+
|
279
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
280
|
+
|
281
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
282
|
+
|
283
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
284
|
+
|
285
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
Application Trace | Framework Trace | Full Trace
|
298
|
+
|
299
|
+
app/views/items/_item.html.erb:1
|
300
|
+
|
301
|
+
app/views/items/index.html.erb:7
|
302
|
+
|
303
|
+
app/views/items/index.html.erb:6:in `each'
|
304
|
+
|
305
|
+
app/views/items/index.html.erb:6
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
➡︎4パターン目をitem.image.url使った場合
|
310
|
+
|
311
|
+
NoMethodError in Items#index
|
312
|
+
|
313
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fee7f6197c8>
|
318
|
+
|
319
|
+
Extracted source (around line #1):
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
324
|
+
|
325
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
326
|
+
|
327
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
328
|
+
|
329
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
330
|
+
|
331
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
332
|
+
|
333
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
Application Trace | Framework Trace | Full Trace
|
346
|
+
|
347
|
+
app/views/items/_item.html.erb:1
|
348
|
+
|
349
|
+
app/views/items/index.html.erb:7
|
350
|
+
|
351
|
+
app/views/items/index.html.erb:6:in `each'
|
352
|
+
|
353
|
+
app/views/items/index.html.erb:6
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
➡︎5パターン目@item.image.urlを使った場合
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
NoMethodError in Items#index
|
362
|
+
|
363
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
undefined method `image' for nil:NilClass
|
368
|
+
|
369
|
+
Extracted source (around line #1):
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
374
|
+
|
375
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
376
|
+
|
377
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
378
|
+
|
379
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
380
|
+
|
381
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
382
|
+
|
383
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
Application Trace | Framework Trace | Full Trace
|
396
|
+
|
397
|
+
app/views/items/_item.html.erb:1
|
398
|
+
|
399
|
+
app/views/items/index.html.erb:7
|
400
|
+
|
401
|
+
app/views/items/index.html.erb:6:in `each'
|
402
|
+
|
403
|
+
app/views/items/index.html.erb:6
|
150
404
|
|
151
405
|
|
152
406
|
|
@@ -154,348 +408,48 @@
|
|
154
408
|
|
155
409
|
|
156
410
|
|
157
|
-
|
411
|
+
補足
|
158
412
|
|
159
413
|
```
|
160
414
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
192
|
-
|
193
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
194
|
-
|
195
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
196
|
-
|
197
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
198
|
-
|
199
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
200
|
-
|
201
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
Application Trace | Framework Trace | Full Trace
|
214
|
-
|
215
|
-
app/views/items/_item.html.erb:1
|
216
|
-
|
217
|
-
app/views/items/index.html.erb:7
|
218
|
-
|
219
|
-
app/views/items/index.html.erb:6:in `each'
|
220
|
-
|
221
|
-
app/views/items/index.html.erb:6
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
➡︎2パターン目image_pathを使った場合
|
228
|
-
|
229
|
-
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
230
|
-
|
231
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
The asset "" is not present in the asset pipeline.
|
236
|
-
|
237
|
-
Extracted source (around line #1):
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
<div class="content_post" style="background-image: url(<%= image_path item.image %>) ;">
|
244
|
-
|
245
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
246
|
-
|
247
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
248
|
-
|
249
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
250
|
-
|
251
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
252
|
-
|
253
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
Application Trace | Framework Trace | Full Trace
|
266
|
-
|
267
|
-
app/views/items/_item.html.erb:1
|
268
|
-
|
269
|
-
app/views/items/index.html.erb:7
|
270
|
-
|
271
|
-
app/views/items/index.html.erb:6:in `each'
|
272
|
-
|
273
|
-
app/views/items/index.html.erb:6
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
➡︎3パターン目をitem.image.path使った場合
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
NoMethodError in Items#index
|
282
|
-
|
283
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
undefined method `path' for #<ActiveStorage::Attached::One:0x00007fee7e66ff70>
|
288
|
-
|
289
|
-
Extracted source (around line #1):
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
<div class="content_post" style="background-image: url(<%= item.image.path %>) ;">
|
294
|
-
|
295
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
296
|
-
|
297
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
298
|
-
|
299
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
300
|
-
|
301
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
302
|
-
|
303
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
Application Trace | Framework Trace | Full Trace
|
316
|
-
|
317
|
-
app/views/items/_item.html.erb:1
|
318
|
-
|
319
|
-
app/views/items/index.html.erb:7
|
320
|
-
|
321
|
-
app/views/items/index.html.erb:6:in `each'
|
322
|
-
|
323
|
-
app/views/items/index.html.erb:6
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
➡︎4パターン目をitem.image.url使った場合
|
328
|
-
|
329
|
-
NoMethodError in Items#index
|
330
|
-
|
331
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fee7f6197c8>
|
336
|
-
|
337
|
-
Extracted source (around line #1):
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
342
|
-
|
343
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
344
|
-
|
345
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
346
|
-
|
347
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
348
|
-
|
349
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
350
|
-
|
351
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
Application Trace | Framework Trace | Full Trace
|
364
|
-
|
365
|
-
app/views/items/_item.html.erb:1
|
366
|
-
|
367
|
-
app/views/items/index.html.erb:7
|
368
|
-
|
369
|
-
app/views/items/index.html.erb:6:in `each'
|
370
|
-
|
371
|
-
app/views/items/index.html.erb:6
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
➡︎5パターン目@item.image.urlを使った場合
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
NoMethodError in Items#index
|
382
|
-
|
383
|
-
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
undefined method `image' for nil:NilClass
|
388
|
-
|
389
|
-
Extracted source (around line #1):
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
396
|
-
|
397
|
-
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
398
|
-
|
399
|
-
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
400
|
-
|
401
|
-
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
402
|
-
|
403
|
-
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
404
|
-
|
405
|
-
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
Application Trace | Framework Trace | Full Trace
|
418
|
-
|
419
|
-
app/views/items/_item.html.erb:1
|
420
|
-
|
421
|
-
app/views/items/index.html.erb:7
|
422
|
-
|
423
|
-
app/views/items/index.html.erb:6:in `each'
|
424
|
-
|
425
|
-
app/views/items/index.html.erb:6
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
415
|
+
S3はバケットを作成して、バケットポリシーを編集、
|
416
|
+
|
417
|
+
Gemfieにgem "aws-sdk-s3", require: falseをbundle installしました。
|
418
|
+
|
419
|
+
その後config/enviroments/delopment.rbにconfig.active_storage.service = :amazonにlocalから変更。
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
次に「パブリックアクセスをすべてブロック」のチェックを外す。
|
424
|
+
|
425
|
+
新規のパブリックバケットポリシー,任意のバケットポリシーにチェックを入れました。
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
config/storage.ymlに追記
|
430
|
+
|
431
|
+
amazon:
|
432
|
+
|
433
|
+
service: S3
|
434
|
+
|
435
|
+
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
436
|
+
|
437
|
+
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
438
|
+
|
439
|
+
region: ap-northeast-1
|
440
|
+
|
441
|
+
bucket: 自身のバケット名
|
434
442
|
|
435
443
|
```
|
436
444
|
|
437
445
|
|
438
446
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
a
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
d
|
448
|
-
|
449
|
-
# Item.create(item_params)
|
450
|
-
|
451
|
-
# binding.pry
|
452
|
-
|
453
|
-
item =Item.new(item_params)
|
454
|
-
|
455
|
-
if item.save
|
456
|
-
|
457
|
-
redirect_to root_path
|
458
|
-
|
459
|
-
else
|
460
|
-
|
461
|
-
render "item/new"
|
462
|
-
|
463
|
-
end
|
464
|
-
|
465
|
-
# アイテムモデル保存する
|
466
|
-
|
467
|
-
# praivateでitem_paramsで引用してくるものを指定
|
468
|
-
|
469
|
-
end
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
S3はバケットを作成して、バケットポリシーを編集、
|
474
|
-
|
475
|
-
Gemfieにgem "aws-sdk-s3", require: falseをbundle installしました。
|
476
|
-
|
477
|
-
その後config/enviroments/delopment.rbにconfig.active_storage.service = :amazonにlocalから変更。
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
次に「パブリックアクセスをすべてブロック」のチェックを外す。
|
482
|
-
|
483
|
-
新規のパブリックバケットポリシー,任意のバケットポリシーにチェックを入れました。
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
config/storage.ymlに追記
|
488
|
-
|
489
|
-
amazon:
|
490
|
-
|
491
|
-
service: S3
|
492
|
-
|
493
|
-
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
494
|
-
|
495
|
-
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
496
|
-
|
497
|
-
region: ap-northeast-1
|
498
|
-
|
499
|
-
bucket: 自身のバケット名
|
500
|
-
|
501
|
-
```
|
447
|
+
追記11/6 20:42
|
448
|
+
|
449
|
+
1)S3にsaveできたというのは、WEBページのAWSのS3のオブジェクトで確認しました。
|
450
|
+
|
451
|
+
2)item_params の中身 => <ActionController::Parameters {"text"=>"パンツ", "image"=>#<ActionDispatch::Http::UploadedFile:0x00007fefc2b84c78 @tempfile=#<Tempfile:/var/folders/qp/vfswzv852_x8zy3q27gp1gt00000gn/T/RackMultipart20201106-6566-1l80iav.png>, @original_filename="スクリーンショット 2020-11-06 19.46.55.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"item[image]\"; filename=\"\xE3\x82\xB9\xE3\x82\xAF\xE3\x83\xAA\xE3\x83\xBC\xE3\x83\xB3\xE3\x82\xB7\xE3\x83\xA7\xE3\x83\x83\xE3\x83\x88 2020-11-06 19.46.55.png\"\r\nContent-Type: image/png\r\n">, "user_id"=>1} permitted: true>
|
452
|
+
|
453
|
+
3)item modelの定義
|
454
|
+
|
455
|
+
params.require(:item).permit(:text, :image ).merge(user_id: current_user.id
|
8
➡︎5パターン目@item.image.urlを使った場合を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -374,6 +374,58 @@
|
|
374
374
|
|
375
375
|
|
376
376
|
|
377
|
+
➡︎5パターン目@item.image.urlを使った場合
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
NoMethodError in Items#index
|
382
|
+
|
383
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
undefined method `image' for nil:NilClass
|
388
|
+
|
389
|
+
Extracted source (around line #1):
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<div class="content_post" style="background-image: url(' <%= image_tag(@item.image.url) %>') ;">
|
396
|
+
|
397
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
398
|
+
|
399
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
400
|
+
|
401
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
402
|
+
|
403
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
404
|
+
|
405
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
Application Trace | Framework Trace | Full Trace
|
418
|
+
|
419
|
+
app/views/items/_item.html.erb:1
|
420
|
+
|
421
|
+
app/views/items/index.html.erb:7
|
422
|
+
|
423
|
+
app/views/items/index.html.erb:6:in `each'
|
424
|
+
|
425
|
+
app/views/items/index.html.erb:6
|
426
|
+
|
427
|
+
|
428
|
+
|
377
429
|
|
378
430
|
|
379
431
|
|
7
item.image.urlを使った場合のエラー
test
CHANGED
File without changes
|
test
CHANGED
@@ -324,7 +324,53 @@
|
|
324
324
|
|
325
325
|
|
326
326
|
|
327
|
-
➡︎4パターン目を使った場合
|
327
|
+
➡︎4パターン目をitem.image.url使った場合
|
328
|
+
|
329
|
+
NoMethodError in Items#index
|
330
|
+
|
331
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
undefined method `url' for #<ActiveStorage::Attached::One:0x00007fee7f6197c8>
|
336
|
+
|
337
|
+
Extracted source (around line #1):
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
<div class="content_post" style="background-image: url(<%= item.image.url %>) ;">
|
342
|
+
|
343
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
344
|
+
|
345
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
346
|
+
|
347
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
348
|
+
|
349
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
350
|
+
|
351
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
Application Trace | Framework Trace | Full Trace
|
364
|
+
|
365
|
+
app/views/items/_item.html.erb:1
|
366
|
+
|
367
|
+
app/views/items/index.html.erb:7
|
368
|
+
|
369
|
+
app/views/items/index.html.erb:6:in `each'
|
370
|
+
|
371
|
+
app/views/items/index.html.erb:6
|
372
|
+
|
373
|
+
|
328
374
|
|
329
375
|
|
330
376
|
|
6
item.image.pathを使用後、エラー
test
CHANGED
File without changes
|
test
CHANGED
@@ -274,7 +274,59 @@
|
|
274
274
|
|
275
275
|
|
276
276
|
|
277
|
+
➡︎3パターン目をitem.image.path使った場合
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
NoMethodError in Items#index
|
282
|
+
|
283
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
undefined method `path' for #<ActiveStorage::Attached::One:0x00007fee7e66ff70>
|
288
|
+
|
289
|
+
Extracted source (around line #1):
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
<div class="content_post" style="background-image: url(<%= item.image.path %>) ;">
|
294
|
+
|
295
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
296
|
+
|
297
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
298
|
+
|
299
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
300
|
+
|
301
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
302
|
+
|
303
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
Application Trace | Framework Trace | Full Trace
|
316
|
+
|
317
|
+
app/views/items/_item.html.erb:1
|
318
|
+
|
319
|
+
app/views/items/index.html.erb:7
|
320
|
+
|
321
|
+
app/views/items/index.html.erb:6:in `each'
|
322
|
+
|
323
|
+
app/views/items/index.html.erb:6
|
324
|
+
|
325
|
+
|
326
|
+
|
277
|
-
➡︎
|
327
|
+
➡︎4パターン目を使った場合
|
328
|
+
|
329
|
+
|
278
330
|
|
279
331
|
|
280
332
|
|
5
エラーの詳細を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -174,25 +174,107 @@
|
|
174
174
|
|
175
175
|
|
176
176
|
|
177
|
-
➡︎
|
177
|
+
➡︎1パターン目image_urlを使った場合
|
178
178
|
|
179
179
|
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
180
180
|
|
181
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
The asset "" is not present in the asset pipeline.
|
186
|
+
|
187
|
+
Extracted source (around line #1):
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
192
|
+
|
193
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
194
|
+
|
195
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
196
|
+
|
197
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
198
|
+
|
199
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
200
|
+
|
201
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
Application Trace | Framework Trace | Full Trace
|
214
|
+
|
215
|
+
app/views/items/_item.html.erb:1
|
216
|
+
|
217
|
+
app/views/items/index.html.erb:7
|
218
|
+
|
219
|
+
app/views/items/index.html.erb:6:in `each'
|
220
|
+
|
221
|
+
app/views/items/index.html.erb:6
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
➡︎2パターン目image_pathを使った場合
|
228
|
+
|
229
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
230
|
+
|
231
|
+
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line #1 raised:
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
The asset "" is not present in the asset pipeline.
|
236
|
+
|
237
|
+
Extracted source (around line #1):
|
238
|
+
|
239
|
+
|
240
|
+
|
181
241
|
|
182
242
|
|
183
243
|
<div class="content_post" style="background-image: url(<%= image_path item.image %>) ;">
|
184
244
|
|
185
|
-
|
245
|
+
<%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
246
|
+
|
186
|
-
|
247
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
248
|
+
|
249
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
250
|
+
|
251
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
252
|
+
|
187
|
-
|
253
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
254
|
+
|
255
|
+
|
256
|
+
|
188
|
-
|
257
|
+
Trace of template inclusion: #<ActionView::Template app/views/items/index.html.erb locals=[]>
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
Rails.root: /Users/uraokayuutarou/projects/nostalgia
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
Application Trace | Framework Trace | Full Trace
|
266
|
+
|
267
|
+
app/views/items/_item.html.erb:1
|
268
|
+
|
189
|
-
|
269
|
+
app/views/items/index.html.erb:7
|
270
|
+
|
190
|
-
|
271
|
+
app/views/items/index.html.erb:6:in `each'
|
272
|
+
|
191
|
-
|
273
|
+
app/views/items/index.html.erb:6
|
274
|
+
|
275
|
+
|
276
|
+
|
192
|
-
|
277
|
+
➡︎3パターン目を使った場合
|
193
|
-
|
194
|
-
|
195
|
-
|
196
278
|
|
197
279
|
|
198
280
|
|
@@ -236,4 +318,34 @@
|
|
236
318
|
|
237
319
|
end
|
238
320
|
|
321
|
+
|
322
|
+
|
323
|
+
S3はバケットを作成して、バケットポリシーを編集、
|
324
|
+
|
325
|
+
Gemfieにgem "aws-sdk-s3", require: falseをbundle installしました。
|
326
|
+
|
327
|
+
その後config/enviroments/delopment.rbにconfig.active_storage.service = :amazonにlocalから変更。
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
次に「パブリックアクセスをすべてブロック」のチェックを外す。
|
332
|
+
|
333
|
+
新規のパブリックバケットポリシー,任意のバケットポリシーにチェックを入れました。
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
config/storage.ymlに追記
|
338
|
+
|
339
|
+
amazon:
|
340
|
+
|
341
|
+
service: S3
|
342
|
+
|
343
|
+
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
344
|
+
|
345
|
+
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
346
|
+
|
347
|
+
region: ap-northeast-1
|
348
|
+
|
349
|
+
bucket: 自身のバケット名
|
350
|
+
|
239
|
-
```
|
351
|
+
```
|
4
image_pathでトライ
test
CHANGED
File without changes
|
test
CHANGED
@@ -180,6 +180,20 @@
|
|
180
180
|
|
181
181
|
|
182
182
|
|
183
|
+
<div class="content_post" style="background-image: url(<%= image_path item.image %>) ;">
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
➡︎エラー発生
|
188
|
+
|
189
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
183
197
|
|
184
198
|
|
185
199
|
|
3
image_urlでトライ
test
CHANGED
File without changes
|
test
CHANGED
@@ -162,8 +162,26 @@
|
|
162
162
|
|
163
163
|
|
164
164
|
|
165
|
+
<code>
|
166
|
+
|
165
167
|
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
166
168
|
|
169
|
+
画像が表示されず、エラーなし
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<div class="content_post" style="background-image: url(<%= image_url item.image %>) ;">
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
➡︎エラー発生
|
178
|
+
|
179
|
+
Sprockets::Rails::Helper::AssetNotFound in Items#index
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
167
185
|
|
168
186
|
|
169
187
|
|
2
質問修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,13 +14,17 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
エラーメッセージ
|
18
|
+
|
19
|
+
ActionView::SyntaxErrorInTemplate in ItemsController#index
|
20
|
+
|
17
21
|
|
18
22
|
|
19
23
|
まずactive storageに投稿した画像を保存し表示できるように出来ました。
|
20
24
|
|
21
|
-
次にAWSのS3に投稿して画像を保存して表示させようとすると、エラー
|
25
|
+
次にAWSのS3に投稿して画像を保存して表示させようとすると、エラーが発生し、
|
22
|
-
|
26
|
+
|
23
|
-
HTMLの記述を修正
|
27
|
+
HTMLの記述を修正しました。
|
24
28
|
|
25
29
|
|
26
30
|
|
@@ -44,7 +48,105 @@
|
|
44
48
|
|
45
49
|
|
46
50
|
|
51
|
+
<code>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
➡︎このコードだと画像が表示されない<div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
56
|
+
|
47
|
-
|
57
|
+
➡︎このコードだとエラーが発生<%# <div class="content_post" style="background-image: url(<%= Rails.apコーフ度plication.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
58
|
+
|
59
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
60
|
+
|
61
|
+
<%# <%= image_tag message.image, class: 'message-image' if message.image.attached? %>
|
62
|
+
|
63
|
+
<%# attached?メソッド レコードにファイルが添付されているかどうか モデル.ファイル名.attached? %>
|
64
|
+
|
65
|
+
<%# image_tagメソッド img要素を生成するRailsのヘルパーメソッド %>
|
66
|
+
|
67
|
+
<%# image_tagメソッドでは、複雑なRailsのディレクトリパスを指定しなくても、モデルから画像ファイルを呼び出して引数に記述するだけで、画像を表示するimg要素を生成 %>
|
68
|
+
|
69
|
+
<div class="more">
|
70
|
+
|
71
|
+
<span><%= image_tag 'arrow_top.png'%></span>
|
72
|
+
|
73
|
+
<ul class="more_list">
|
74
|
+
|
75
|
+
<li>
|
76
|
+
|
77
|
+
<%= link_to '詳細', item_path(item.id), method: :get%>
|
78
|
+
|
79
|
+
</li>
|
80
|
+
|
81
|
+
<% if user_signed_in? && current_user.id == item.user_id %>
|
82
|
+
|
83
|
+
<li>
|
84
|
+
|
85
|
+
<%= link_to '削除', item_path(item.id), method: :delete %>
|
86
|
+
|
87
|
+
</li>
|
88
|
+
|
89
|
+
<%# Prefixの引数 %>
|
90
|
+
|
91
|
+
<%# アイテムのID(item.id) %>
|
92
|
+
|
93
|
+
<%# HTTPメソッドは、DELETEというHTTPメソッド %>
|
94
|
+
|
95
|
+
<%# methodオプションにシンボルで:delete %>
|
96
|
+
|
97
|
+
<li>
|
98
|
+
|
99
|
+
<%= link_to '編集',edit_item_path(item.id), method: :get %>
|
100
|
+
|
101
|
+
<%# get サーバーからブラウザに情報を返す。単にウェブサイトを閲覧する際など、情報を取得するために利用される。 %>
|
102
|
+
|
103
|
+
<%# Prefixでパスを確認 %>
|
104
|
+
|
105
|
+
</li>
|
106
|
+
|
107
|
+
<% end %>
|
108
|
+
|
109
|
+
</ul>
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
<p><%= item.text %></p>
|
114
|
+
|
115
|
+
<span class="name">
|
116
|
+
|
117
|
+
<a href="/users/<%= item.user.id %>">
|
118
|
+
|
119
|
+
<span>投稿者</span><%= item.user.nickname %>
|
120
|
+
|
121
|
+
</a>
|
122
|
+
|
123
|
+
</span>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
|
127
|
+
>
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
➡︎エラー内容
|
132
|
+
|
133
|
+
ActionView::SyntaxErrorInTemplate in ItemsController#index
|
134
|
+
|
135
|
+
Extracted source (around line #3):
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<%# <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;"> %>
|
140
|
+
|
141
|
+
<div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached?
|
142
|
+
|
143
|
+
<%# <%= image_tag item.image ,class: 'item-image' if item.image.attached? %>
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
48
150
|
|
49
151
|
|
50
152
|
|
@@ -62,6 +164,10 @@
|
|
62
164
|
|
63
165
|
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
64
166
|
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
65
171
|
```
|
66
172
|
|
67
173
|
|
1
controllerの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,6 +40,10 @@
|
|
40
40
|
|
41
41
|
```Ruby on rails
|
42
42
|
|
43
|
+
app/veiws/veiws/_item.html.erb
|
44
|
+
|
45
|
+
|
46
|
+
|
43
47
|
上記エラーコード()の中身 <%# <div class="content_post" style="background-image: url(<%= Rails.application.routes.url_helpers.url_for(item.image) if item.image.attached? %>
|
44
48
|
|
45
49
|
|
@@ -52,6 +56,46 @@
|
|
52
56
|
|
53
57
|
```
|
54
58
|
|
59
|
+
app/veiws/veiws/_item.html.erb
|
60
|
+
|
61
|
+
|
62
|
+
|
55
63
|
上記修正後のコード()の中身 <div class="content_post" style="background-image: url(<%= image_tag item.image %>) ;">
|
56
64
|
|
57
65
|
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
補足
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
app/controller/items.controller.rb
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
def create
|
78
|
+
|
79
|
+
# Item.create(item_params)
|
80
|
+
|
81
|
+
# binding.pry
|
82
|
+
|
83
|
+
item =Item.new(item_params)
|
84
|
+
|
85
|
+
if item.save
|
86
|
+
|
87
|
+
redirect_to root_path
|
88
|
+
|
89
|
+
else
|
90
|
+
|
91
|
+
render "item/new"
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
# アイテムモデル保存する
|
96
|
+
|
97
|
+
# praivateでitem_paramsで引用してくるものを指定
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
```
|