ScaffoldPlusAnswerTwo » 履歴 » バージョン 9
Yuumi Yoshida, 2008-01-13 17:34
1 | 1 | Yuumi Yoshida | = 演習2解答例 = |
---|---|---|---|
2 | |||
3 | 4 | Yuumi Yoshida | == 作業手順 == |
4 | {{{ |
||
5 | 5 | Yuumi Yoshida | ruby script/generate migration AddMemoToTodo memo:text |
6 | 4 | Yuumi Yoshida | rake db:migrate |
7 | }}} |
||
8 | |||
9 | 1 | Yuumi Yoshida | == 変更点 == |
10 | |||
11 | 9 | Yuumi Yoshida | === 1. app/helpers/todos_helper.rb === |
12 | 3 | Yuumi Yoshida | 改行を<br/>タグに変換する new_lineメッソドを追加 |
13 | {{{ |
||
14 | 7 | Yuumi Yoshida | #!html |
15 | <pre class="wiki">module TodosHelper |
||
16 | |||
17 | <font color="red">def new_line(s) |
||
18 | s.gsub(/\n/, "<br>") |
||
19 | end</font> |
||
20 | |||
21 | end |
||
22 | </pre> |
||
23 | 1 | Yuumi Yoshida | }}} |
24 | |||
25 | === 2. app/views/todos/show.html.erb === |
||
26 | |||
27 | 7 | Yuumi Yoshida | memoカラム表示用のコードを追加 |
28 | 1 | Yuumi Yoshida | {{{ |
29 | 7 | Yuumi Yoshida | #!html |
30 | <pre class="wiki"><p> |
||
31 | <b>Due:</b> |
||
32 | <%25=h @todo.due %25> |
||
33 | </p> |
||
34 | 1 | Yuumi Yoshida | |
35 | 7 | Yuumi Yoshida | <p> |
36 | <b>Task:</b> |
||
37 | <%25=h @todo.task %25> |
||
38 | </p> |
||
39 | 1 | Yuumi Yoshida | |
40 | 7 | Yuumi Yoshida | <font color="red"><p> |
41 | <b>Memo:</b><br/> |
||
42 | <%25=new_line(h(@todo.memo)) %25> |
||
43 | </p></font> |
||
44 | 1 | Yuumi Yoshida | |
45 | 7 | Yuumi Yoshida | <%25= link_to 'Edit', edit_todo_path(@todo) %25> | |
46 | <%25= link_to 'Back', todos_path %25> |
||
47 | </pre> |
||
48 | 1 | Yuumi Yoshida | }}} |
49 | 2 | Yuumi Yoshida | |
50 | 3 | Yuumi Yoshida | === 3. app/views/todos/edit.html.erb === |
51 | 2 | Yuumi Yoshida | |
52 | 8 | Yuumi Yoshida | memoカラム入力用のコードを追加 |
53 | 1 | Yuumi Yoshida | {{{ |
54 | 8 | Yuumi Yoshida | #!html |
55 | <pre class="wiki"><h1>Editing todo</h1> |
||
56 | 1 | Yuumi Yoshida | |
57 | 8 | Yuumi Yoshida | <%25= error_messages_for :todo %25> |
58 | 2 | Yuumi Yoshida | |
59 | 8 | Yuumi Yoshida | <%25 form_for(@todo) do |f| %25> |
60 | <p> |
||
61 | <b>Due</b><br /> |
||
62 | <%25= f.date_select :due %25> |
||
63 | </p> |
||
64 | 1 | Yuumi Yoshida | |
65 | 8 | Yuumi Yoshida | <p> |
66 | <b>Task</b><br /> |
||
67 | <%25= f.text_field :task %25> |
||
68 | </p> |
||
69 | 2 | Yuumi Yoshida | |
70 | 8 | Yuumi Yoshida | <font color="red"><p> |
71 | <b>Memo</b><br /> |
||
72 | <%25= f.text_area :memo %25> |
||
73 | </p></font> |
||
74 | 2 | Yuumi Yoshida | |
75 | 8 | Yuumi Yoshida | <p> |
76 | <%25= f.submit "Update" %25> |
||
77 | </p> |
||
78 | <%25 end %25> |
||
79 | 2 | Yuumi Yoshida | |
80 | 8 | Yuumi Yoshida | <%25= link_to 'Show', @todo %25> | |
81 | <%25= link_to 'Back', todos_path %25> |
||
82 | </pre> |
||
83 | 2 | Yuumi Yoshida | }}} |
84 | |||
85 | === 4. app/views/todos/new.html.erb === |
||
86 | |||
87 | 8 | Yuumi Yoshida | memoカラム入力用のコードを追加 |
88 | 2 | Yuumi Yoshida | {{{ |
89 | 8 | Yuumi Yoshida | #!html |
90 | <pre class="wiki"><h1>New todo</h1> |
||
91 | 2 | Yuumi Yoshida | |
92 | 8 | Yuumi Yoshida | <%25= error_messages_for :todo %25> |
93 | 2 | Yuumi Yoshida | |
94 | 8 | Yuumi Yoshida | <%25 form_for(@todo) do |f| %25> |
95 | <p> |
||
96 | <b>Due</b><br /> |
||
97 | <%25= f.date_select :due %25> |
||
98 | </p> |
||
99 | 2 | Yuumi Yoshida | |
100 | 8 | Yuumi Yoshida | <p> |
101 | <b>Task</b><br /> |
||
102 | <%25= f.text_field :task %25> |
||
103 | </p> |
||
104 | 2 | Yuumi Yoshida | |
105 | 8 | Yuumi Yoshida | <font color="red"><p> |
106 | <b>Memo</b><br /> |
||
107 | <%25= f.text_area :memo %25> |
||
108 | </p></font> |
||
109 | 2 | Yuumi Yoshida | |
110 | 8 | Yuumi Yoshida | <p> |
111 | <%25= f.submit "Create" %25> |
||
112 | </p> |
||
113 | <%25 end %25> |
||
114 | 2 | Yuumi Yoshida | |
115 | 8 | Yuumi Yoshida | <%25= link_to 'Back', todos_path %25> |
116 | </pre> |
||
117 | 1 | Yuumi Yoshida | }}} |
118 | |||
119 | |||
120 | == ソースコード == |
||
121 | |||
122 | 解答例のソースコードは http://www.ey-office.com/trac/rails/browser/tags/todo_q2で参照できます。 |