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