質問編集履歴

1

該当のソースコードに新規登録、編集で使用する`_fomr.html.erb`と一覧画面の`index.html.erb`を追加

2019/01/29 02:29

投稿

ruby510
ruby510

スコア15

test CHANGED
File without changes
test CHANGED
@@ -266,6 +266,172 @@
266
266
 
267
267
 
268
268
 
269
+ ```ruby
270
+
271
+ #<_form.html.erb>
272
+
273
+
274
+
275
+ <% if @user.errors.any? %>
276
+
277
+ <div id="error_explanation">
278
+
279
+ <h2><%= @user.errors.count %>件のエラーがあります。</h2>
280
+
281
+
282
+
283
+ <ul>
284
+
285
+ <% @user.errors.full_messages.each do |message| %>
286
+
287
+ <li><%= message %></li>
288
+
289
+ <% end %>
290
+
291
+ </ul>
292
+
293
+ </div>
294
+
295
+ <% end %>
296
+
297
+
298
+
299
+ <%# ユーザー情報 %>
300
+
301
+ <div class="form">
302
+
303
+ <%= form_for @user do |f| %>
304
+
305
+ <div class="user-form">
306
+
307
+ <div class="field">
308
+
309
+ <%= f.label :name %>
310
+
311
+ <%= f.text_field :name %>
312
+
313
+ </div>
314
+
315
+ <div class="field">
316
+
317
+ <%= f.label :email %>
318
+
319
+ <%= f.text_field :email %>円
320
+
321
+ </div>
322
+
323
+ </div>
324
+
325
+
326
+
327
+ <%# 本情報 %>
328
+
329
+ <div class="book-form">
330
+
331
+ <%= f.fields_for :books do |book| %>
332
+
333
+ <h2>本: <%= book.index+1 %></h2>
334
+
335
+ <div class="field">
336
+
337
+ <%= book.label :title %>
338
+
339
+ <%= book.text_field :title %>
340
+
341
+ </div>
342
+
343
+ <div class="field">
344
+
345
+ <%= book.label :content %>
346
+
347
+ <%= book.text_field :content %>
348
+
349
+ </div>
350
+
351
+ <% end %>
352
+
353
+ </div>
354
+
355
+
356
+
357
+ <div class="actions">
358
+
359
+ <%= f.submit %>
360
+
361
+ </div>
362
+
363
+ <% end %>
364
+
365
+ </div>
366
+
367
+
368
+
369
+ ```
370
+
371
+
372
+
373
+ ```ruby
374
+
375
+ #<index.html.erb>
376
+
377
+ <div class="container">
378
+
379
+ <div class="user-index"></div>
380
+
381
+ <h1>ユーザー一覧</h1>
382
+
383
+
384
+
385
+ <table>
386
+
387
+ <tr>
388
+
389
+ <th id="name">名前</th>
390
+
391
+ <th id="rent">メールアドレス</th>
392
+
393
+ </tr>
394
+
395
+
396
+
397
+ <% @users.each do |user| %>
398
+
399
+ <tr>
400
+
401
+ <td><%= user.name %></td>
402
+
403
+ <td><%= user.email %></td>
404
+
405
+
406
+
407
+ <td><%= link_to "詳細", user_path(user.id) %></td>
408
+
409
+ <td><%= link_to "編集", edit_user_path(user.id) %></td>
410
+
411
+ <td><%= link_to "削除", user_path(user.id), method: :delete, data: { confirm: '本当に編集していいですか?' } %></td>
412
+
413
+ </tr>
414
+
415
+ <% end %>
416
+
417
+ </table>
418
+
419
+
420
+
421
+ <%= link_to "ユーザーを登録する", new_user_path %>
422
+
423
+ </div>
424
+
425
+
426
+
427
+ ```
428
+
429
+
430
+
431
+
432
+
433
+
434
+
269
435
  ### 試したこと
270
436
 
271
437