菜鸟需要一些帮助。我正在为我的孩子创建一个家务图表,它应该看起来像一个在线版本:
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 是 Children 和 Chores Tables 之间的连接表。两个问题:
- 我如何将按钮切换到表格中的框,单击时会变成星星图像(根据示例)?
- 如何重构表中的代码,以免违反 DRY 规则?