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