質問編集履歴

3

viewの追加

2018/06/28 01:04

投稿

kaoru_tujimiya
kaoru_tujimiya

スコア36

test CHANGED
File without changes
test CHANGED
@@ -125,3 +125,89 @@
125
125
  end
126
126
 
127
127
  end
128
+
129
+
130
+
131
+ >>>>>>>>>>>>>>>>>>>>>>>>
132
+
133
+ 追記
134
+
135
+ edit.html.erb のコードです。
136
+
137
+
138
+
139
+ <h1>Cards#edit</h1>
140
+
141
+ <p><%= @card.title %>の内容を編集します。</p>
142
+
143
+ <table>
144
+
145
+ <%= form_for(@card,url:{controller:'cards',action: 'edit',id:'@card.id'}) do |form| %>
146
+
147
+
148
+
149
+ <tr>
150
+
151
+ <th>タイトル</th>
152
+
153
+ <td><%= form.text_field :title, { size:40 } %></td>
154
+
155
+ </tr>
156
+
157
+
158
+
159
+ <tr>
160
+
161
+ <th>著者</th>
162
+
163
+ <td><%= form.text_field :author, { size:40 } %></td>
164
+
165
+ </tr>
166
+
167
+
168
+
169
+ <tr>
170
+
171
+ <th>価格</th>
172
+
173
+ <td><%= form.number_field :price, { size:10 } %></td>
174
+
175
+ </tr>
176
+
177
+
178
+
179
+ <tr>
180
+
181
+ <th>出版社</th>
182
+
183
+ <td><%= form.text_field :publisher, { size:40 } %></td>
184
+
185
+ </tr>
186
+
187
+
188
+
189
+ <tr>
190
+
191
+ <th>コメント</th>
192
+
193
+ <td><%= form.text_area :memo, {cols:40, rows:10} %></td>
194
+
195
+ </tr>
196
+
197
+
198
+
199
+ <tr>
200
+
201
+ <th></th>
202
+
203
+ <td><%= form.submit "更新" %></td>
204
+
205
+ </tr>
206
+
207
+ <% end %>
208
+
209
+ </table>
210
+
211
+
212
+
213
+ <p class="link"><a href="/cards">&lt;&lt;</a></p>

2

見やすさ改善

2018/06/28 01:04

投稿

kaoru_tujimiya
kaoru_tujimiya

スコア36

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  end
32
32
 
33
- ---------------------------------------------------------------------------------
33
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
34
34
 
35
35
  追記
36
36
 

1

Cards_controllerのコードの更新をしました。

2018/06/27 01:27

投稿

kaoru_tujimiya
kaoru_tujimiya

スコア36

test CHANGED
File without changes
test CHANGED
@@ -29,3 +29,99 @@
29
29
  goback
30
30
 
31
31
  end
32
+
33
+ ---------------------------------------------------------------------------------
34
+
35
+ 追記
36
+
37
+ Cards_controllerのコードです。
38
+
39
+
40
+
41
+ class CardsController < ApplicationController
42
+
43
+ layout 'cards'
44
+
45
+
46
+
47
+ def index
48
+
49
+ @cards = Card.all
50
+
51
+ end
52
+
53
+
54
+
55
+ def show
56
+
57
+ @card = Card.find(params[:id])
58
+
59
+ end
60
+
61
+
62
+
63
+ def add
64
+
65
+ if request.post? then
66
+
67
+ Card.create(card_params)
68
+
69
+ goback
70
+
71
+ else
72
+
73
+ @card = Card.new
74
+
75
+ end
76
+
77
+ end
78
+
79
+
80
+
81
+ def edit
82
+
83
+ @card = Card.find(params[:id])
84
+
85
+ if request.patch? then
86
+
87
+ @card.update(card_params)
88
+
89
+ goback
90
+
91
+ end
92
+
93
+ end
94
+
95
+
96
+
97
+ def delete
98
+
99
+ Card.find(params[:id]).destroy
100
+
101
+ goback
102
+
103
+ end
104
+
105
+
106
+
107
+ private
108
+
109
+ def card_params
110
+
111
+ params.require(:card).permit(:title, :author, :price, :publisher, :memo)
112
+
113
+ end
114
+
115
+
116
+
117
+ private
118
+
119
+
120
+
121
+ def goback
122
+
123
+ redirect_to '/cards'
124
+
125
+ end
126
+
127
+ end