【发布时间】:2011-05-11 12:56:08
【问题描述】:
菜鸟需要一些帮助。我正在为我的孩子创建一个看起来像在线版本的家务图表:
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 规则?
【问题讨论】:
标签: ruby-on-rails image link-to