菜单has_many:盘子。在Rails 3中排序关联模型?
我想通过Dish.number对盘子进行分类。
目前在我看来,它看起来像:
<table class="menu">
<% @menu.dishes.each do |dish| %>
<div class="dish">
<tr>
<td>
<div class="dish_div dish_name">
<% if @menu.name != 'Övrigt' && @menu.name != 'Box to go' %>
<span class="dish_name"><%= "#{dish.number}. #{dish.name}" %></span>
<% else %>
<span class="dish_name"><%= "#{dish.name}" %></span>
<% end %>
<% if dish.strength_id == 2 %>
<%= image_tag('chili.png') %>
<% elsif dish.strength_id == 3 %>
<%= image_tag('chili.png') %>
<%= image_tag('chili.png') %>
<% elsif dish.strength_id == 4 %>
<%= image_tag('chili.png') %>
<%= image_tag('chili.png') %>
<%= image_tag('chili.png') %>
<% end %>
</div>
<div class="dish_div"><%= "#{dish.description}" %></div>
<div class="dish_div dish_price"><%= "#{dish.price} kr" %></div>
</td>
</tr>
</div>
<% end %>
</table>
我该怎么办呢?
它应该在视图还是控制器?
感谢
或者,如果你想更具体的'@dishes = @ menu.dishes.all(:为了=> '号DESC')'或'@dish es = @ menu.dishes.all(:order =>'number ASC')' – Norto23 2013-05-01 06:34:42