ScaffoldPlusAnswerTwo » 履歴 » バージョン 12
Yuumi Yoshida, 2008-07-13 17:36
1 | 10 | Yuumi Yoshida | h1. 演習2解答例 |
---|---|---|---|
2 | |||
3 | |||
4 | |||
5 | h2. 作業手順 |
||
6 | |||
7 | 1 | Yuumi Yoshida | <pre> |
8 | 11 | Yuumi Yoshida | ruby script/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 | s.gsub(/\n/, "<br>") |
||
25 | 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 | <%25=h @todo.due %25> |
||
40 | </p> |
||
41 | 1 | Yuumi Yoshida | |
42 | 11 | Yuumi Yoshida | <p> |
43 | <b>Task:</b> |
||
44 | <%25=h @todo.task %25> |
||
45 | </p> |
||
46 | 1 | Yuumi Yoshida | |
47 | 11 | Yuumi Yoshida | ##(<p> |
48 | <b>Memo:</b><br/> |
||
49 | <%25=new_line(h(@todo.memo)) %25> |
||
50 | </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 | 10 | Yuumi Yoshida | h3. 3. app/views/todos/edit.html.erb |
59 | |||
60 | 8 | Yuumi Yoshida | |
61 | memoカラム入力用のコードを追加 |
||
62 | 11 | Yuumi Yoshida | <pre><code class="color"> |
63 | <h1>Editing todo</h1> |
||
64 | 8 | Yuumi Yoshida | |
65 | 11 | Yuumi Yoshida | <%25= error_messages_for :todo %25> |
66 | 8 | Yuumi Yoshida | |
67 | 11 | Yuumi Yoshida | <%25 form_for(@todo) do |f| %25> |
68 | <p> |
||
69 | <b>Due</b><br /> |
||
70 | <%25= f.date_select :due %25> |
||
71 | </p> |
||
72 | 2 | Yuumi Yoshida | |
73 | 11 | Yuumi Yoshida | <p> |
74 | <b>Task</b><br /> |
||
75 | <%25= f.text_field :task %25> |
||
76 | </p> |
||
77 | 1 | Yuumi Yoshida | |
78 | 11 | Yuumi Yoshida | ##(<p> |
79 | <b>Memo</b><br /> |
||
80 | <%25= f.text_area :memo %25> |
||
81 | </p>)## |
||
82 | 2 | Yuumi Yoshida | |
83 | 11 | Yuumi Yoshida | <p> |
84 | <%25= f.submit "Update" %25> |
||
85 | </p> |
||
86 | <%25 end %25> |
||
87 | 2 | Yuumi Yoshida | |
88 | 11 | Yuumi Yoshida | <%25= link_to 'Show', @todo %25> | |
89 | <%25= link_to 'Back', todos_path %25> |
||
90 | 8 | Yuumi Yoshida | |
91 | 11 | Yuumi Yoshida | </code></pre> |
92 | 10 | Yuumi Yoshida | |
93 | 11 | Yuumi Yoshida | |
94 | 10 | Yuumi Yoshida | h3. 4. app/views/todos/new.html.erb |
95 | 8 | Yuumi Yoshida | |
96 | 10 | Yuumi Yoshida | |
97 | 2 | Yuumi Yoshida | memoカラム入力用のコードを追加 |
98 | 11 | Yuumi Yoshida | <pre><code class="color"> |
99 | <h1>New todo</h1> |
||
100 | 8 | Yuumi Yoshida | |
101 | 11 | Yuumi Yoshida | <%25= error_messages_for :todo %25> |
102 | 8 | Yuumi Yoshida | |
103 | 11 | Yuumi Yoshida | <%25 form_for(@todo) do |f| %25> |
104 | <p> |
||
105 | <b>Due</b><br /> |
||
106 | <%25= f.date_select :due %25> |
||
107 | </p> |
||
108 | 1 | Yuumi Yoshida | |
109 | 11 | Yuumi Yoshida | <p> |
110 | <b>Task</b><br /> |
||
111 | <%25= f.text_field :task %25> |
||
112 | </p> |
||
113 | 8 | Yuumi Yoshida | |
114 | 11 | Yuumi Yoshida | ##(<p> |
115 | <b>Memo</b><br /> |
||
116 | <%25= f.text_area :memo %25> |
||
117 | </p>)## |
||
118 | 8 | Yuumi Yoshida | |
119 | 11 | Yuumi Yoshida | <p> |
120 | <%25= f.submit "Create" %25> |
||
121 | </p> |
||
122 | <%25 end %25> |
||
123 | 8 | Yuumi Yoshida | |
124 | 11 | Yuumi Yoshida | <%25= link_to 'Back', todos_path %25> |
125 | </code></pre> |
||
126 | 8 | Yuumi Yoshida | |
127 | 1 | Yuumi Yoshida | |
128 | 10 | Yuumi Yoshida | |
129 | h2. ソースコード |
||
130 | |||
131 | 1 | Yuumi Yoshida | |
132 | 12 | Yuumi Yoshida | 解答例のソースコードは http://www.ey-office.com/trac/rails/browser/tags/todo_q2 で参照できます。 |