助けが必要なNoob。私は私の子供のための雑用チャートを作成しています。これはオンラインバージョンのように見えるはずです。
http://learningandeducationtoys.guidestobuy.com/i-can-do-it-reward-chart
雑用はY軸の下にリストされ、日(日、月...)はX軸の上にリストされます。子供がクリックして、完了した雑用の星を受け取るためのボックス。
chores / index.html.erbテーブルは醜いコードです(申し訳ありません):
雑用の一覧表示
<table>
<th><%= "" %></th>
<th><%= "SUN" %></th>
<th><%= "MON" %></th>
<th><%= "TUES" %></th>
<th><%= "WED" %></th>
<th><%= "THURS" %></th>
<th><%= "FRI" %></th>
<th><%= "SAT" %></th>
<% @chores.each do |chore| %>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<% ##TODO.. Fix to be sure to link "post" action to "show" child. %>
<td>
<%= image_tag(chore.image_url, :class => 'list-image') %>
<dt><%=h chore.title %></dt>
</td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
<td class="button"><%= button_to "Add to Wallet", wallets_path(:chore_id => chore, :child_id => session[:child_id]),
:remote => true %></td>
</tr>
<% end %>
</table>
</div>
上記は、毎日の雑用ごとに「ウォレットに追加」ボタンを作成します。Walletsは、ChildrenTablesとChoresTablesの間の結合テーブルです。2つの質問:
- ボタンをテーブル内のボックスに切り替えるにはどうすればよいですか?クリックすると、星の画像に変わります(例のように)?
- DRYルールに違反しないように、テーブル内のコードをリファクタリングするにはどうすればよいですか?