回答編集履歴
1
posts_controller.rbに関して追記。
test
CHANGED
@@ -13,3 +13,41 @@
|
|
13
13
|
<img src="<%= "/post_images/#{post.post_image}" %>">
|
14
14
|
|
15
15
|
```
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
【追記】
|
22
|
+
|
23
|
+
`posts_controller.rb`の`if @post.save`以下をこの様に変更してみてはいかかでしょうか。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```Ruby
|
28
|
+
|
29
|
+
if @post.save
|
30
|
+
|
31
|
+
if params[:post_image]
|
32
|
+
|
33
|
+
@post.post_image = "#{@post.id}.jpg"
|
34
|
+
|
35
|
+
post_image = params[:post_image]
|
36
|
+
|
37
|
+
File.binwrite("public/post_images/#{@post.post_image}", post_image.read)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
@post.save
|
42
|
+
|
43
|
+
flash[:notice] = "投稿を作成しました"
|
44
|
+
|
45
|
+
redirect_to("/posts/index")
|
46
|
+
|
47
|
+
else
|
48
|
+
|
49
|
+
render("posts/new")
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
```
|