ScaffoldPlusAnswerTwo » 履歴 » バージョン 20
Yuumi Yoshida, 2015-08-03 22:24
1 | 20 | Yuumi Yoshida | # 演習2解答例 |
---|---|---|---|
2 | 10 | Yuumi Yoshida | |
3 | |||
4 | |||
5 | 20 | Yuumi Yoshida | ## 作業手順 |
6 | 10 | Yuumi Yoshida | |
7 | 20 | Yuumi Yoshida | ~~~ |
8 | 18 | Yuumi Yoshida | rails generate migration AddMemoToTodo memo:text |
9 | 1 | Yuumi Yoshida | rake db:migrate |
10 | 20 | Yuumi Yoshida | ~~~ |
11 | 1 | Yuumi Yoshida | |
12 | |||
13 | 20 | Yuumi Yoshida | ## 変更点 |
14 | 1 | Yuumi Yoshida | |
15 | 10 | Yuumi Yoshida | |
16 | |||
17 | 20 | Yuumi Yoshida | ### 1. app/helpers/todos_helper.rb |
18 | 10 | Yuumi Yoshida | |
19 | 1 | Yuumi Yoshida | 改行を<br/>タグに変換する new_lineメッソドを追加 |
20 | 20 | Yuumi Yoshida | |
21 | ~~~ |
||
22 | 11 | Yuumi Yoshida | module TodosHelper |
23 | ##( |
||
24 | 1 | Yuumi Yoshida | def new_line(s) |
25 | 14 | Yuumi Yoshida | raw(html_escape(s).gsub(/\n/, "<br>")) |
26 | 11 | Yuumi Yoshida | end |
27 | 1 | Yuumi Yoshida | )## |
28 | end |
||
29 | 20 | Yuumi Yoshida | ~~~ |
30 | 1 | Yuumi Yoshida | |
31 | 7 | Yuumi Yoshida | |
32 | 1 | Yuumi Yoshida | |
33 | 20 | Yuumi Yoshida | ### 2. app/views/todos/show.html.erb |
34 | 1 | Yuumi Yoshida | |
35 | |||
36 | 10 | Yuumi Yoshida | memoカラム表示用のコードを追加 |
37 | 20 | Yuumi Yoshida | |
38 | ~~~ |
||
39 | 1 | Yuumi Yoshida | <p> |
40 | <b>Due:</b> |
||
41 | 20 | Yuumi Yoshida | <%= @todo.due %> |
42 | 1 | Yuumi Yoshida | </p> |
43 | |||
44 | 11 | Yuumi Yoshida | <p> |
45 | 1 | Yuumi Yoshida | <b>Task:</b> |
46 | 20 | Yuumi Yoshida | <%= @todo.task %> |
47 | 1 | Yuumi Yoshida | </p> |
48 | |||
49 | ##(<p> |
||
50 | <b>Memo:</b><br/> |
||
51 | 20 | Yuumi Yoshida | <%=new_line(@todo.memo) %> |
52 | 1 | Yuumi Yoshida | </p>)## |
53 | |||
54 | 20 | Yuumi Yoshida | <%= link_to 'Edit', edit_todo_path(@todo) %> | |
55 | <%= link_to 'Back', todos_path %> |
||
56 | 1 | Yuumi Yoshida | |
57 | 20 | Yuumi Yoshida | ~~~ |
58 | 1 | Yuumi Yoshida | |
59 | 8 | Yuumi Yoshida | |
60 | 20 | Yuumi Yoshida | ### 3. app/views/todos/_form.html.erb |
61 | 1 | Yuumi Yoshida | |
62 | |||
63 | memoカラム入力用のコードを追加 |
||
64 | 20 | Yuumi Yoshida | |
65 | ~~~ |
||
66 | <%= form_for(@todo) do |f| %> |
||
67 | <% if @todo.errors.any? %> |
||
68 | 1 | Yuumi Yoshida | <div id="error_explanation"> |
69 | 20 | Yuumi Yoshida | <h2><%= pluralize(@todo.errors.count, "error") %> prohibited this todo from being saved:</h2> |
70 | 15 | Yuumi Yoshida | |
71 | <ul> |
||
72 | 20 | Yuumi Yoshida | <% @todo.errors.full_messages.each do |msg| %> |
73 | <li><%= msg %></li> |
||
74 | <% end %> |
||
75 | 15 | Yuumi Yoshida | </ul> |
76 | 11 | Yuumi Yoshida | </div> |
77 | 20 | Yuumi Yoshida | <% end %> |
78 | 15 | Yuumi Yoshida | |
79 | 8 | Yuumi Yoshida | <div class="field"> |
80 | 20 | Yuumi Yoshida | <%= f.label :due %><br /> |
81 | <%= f.date_select :due %> |
||
82 | 15 | Yuumi Yoshida | </div> |
83 | 1 | Yuumi Yoshida | <div class="field"> |
84 | 20 | Yuumi Yoshida | <%= f.label :task %><br /> |
85 | <%= f.text_field :task %> |
||
86 | 15 | Yuumi Yoshida | </div> |
87 | 1 | Yuumi Yoshida | ##(<div class="field"> |
88 | 20 | Yuumi Yoshida | <%= f.label :memo %><br /> |
89 | <%= f.text_area :memo %> |
||
90 | 15 | Yuumi Yoshida | </div>)## |
91 | <div class="actions"> |
||
92 | 20 | Yuumi Yoshida | <%= f.submit %> |
93 | 1 | Yuumi Yoshida | </div> |
94 | 20 | Yuumi Yoshida | <% end %> |
95 | ~~~ |