質問編集履歴
3
タイトルの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
新規投稿でのエラーメッセージが表示されない。
|
1
|
+
【Ruby on Rails】新規投稿でのエラーメッセージが表示されない。
|
test
CHANGED
File without changes
|
2
viewのコードを全体に変更しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,26 @@
|
|
24
24
|
|
25
25
|
```ここに言語名を入力
|
26
26
|
|
27
|
+
<section class="hero is-success">
|
28
|
+
|
29
|
+
<div class="hero-body">
|
30
|
+
|
31
|
+
<div class="container">
|
32
|
+
|
33
|
+
<h1 class="title">
|
34
|
+
|
35
|
+
ゲーム記事作成
|
36
|
+
|
37
|
+
</h1>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
</div>
|
42
|
+
|
43
|
+
</section>
|
44
|
+
|
45
|
+
|
46
|
+
|
27
47
|
<% if @game.errors.any? %>
|
28
48
|
|
29
49
|
<div class="notification is-danger">
|
@@ -43,6 +63,60 @@
|
|
43
63
|
</div>
|
44
64
|
|
45
65
|
<% end %>
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<section class="section">
|
70
|
+
|
71
|
+
<div class="container">
|
72
|
+
|
73
|
+
<div class="columns is-centered">
|
74
|
+
|
75
|
+
<div class="column is-6">
|
76
|
+
|
77
|
+
<%= form_with model: @game do |f| %>
|
78
|
+
|
79
|
+
<div class="field">
|
80
|
+
|
81
|
+
<%= f.label :title, "ゲーム名", class: "label" %>
|
82
|
+
|
83
|
+
<%= f.text_field :title, class: "input" %>
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<div class="field">
|
90
|
+
|
91
|
+
<%= f.label :body, "楽しみ方", class: "label" %>
|
92
|
+
|
93
|
+
<%= f.text_area :body, class: "textarea" %>
|
94
|
+
|
95
|
+
</div>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
<div class="field">
|
100
|
+
|
101
|
+
<%= f.label :image, "写真", class: "label" %>
|
102
|
+
|
103
|
+
<%= f.attachment_field :image, class: "input" %>
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<%= f.submit "投稿", class: "button is-success" %>
|
110
|
+
|
111
|
+
<% end %>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
</div>
|
118
|
+
|
119
|
+
</section>
|
46
120
|
|
47
121
|
```
|
48
122
|
|
1
コントローラーの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,6 +48,38 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
+
```
|
52
|
+
|
53
|
+
def new
|
54
|
+
|
55
|
+
@game = Game.new
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
def create
|
62
|
+
|
63
|
+
@game = Game.new(game_params)
|
64
|
+
|
65
|
+
@game.user_id = current_user.id
|
66
|
+
|
67
|
+
if @game.save
|
68
|
+
|
69
|
+
redirect_to game_path(@game), notice: "投稿に成功しました。"
|
70
|
+
|
71
|
+
else
|
72
|
+
|
73
|
+
render :new
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
51
83
|
### 試したこと
|
52
84
|
|
53
85
|
|