1.可以用ransack gem工具
2.遍历显示each之前进行排序
实际案例:
<% @subject.rooms_subjects.order("rooms_subjects.position desc").each do |f| %>
<tr>
<td><%= f.room.id %></td>
<td><%= f.room.number %></td>
<td><%= f.room.name %></td>
<td><%= f.room.country_code %></td>
<td><%= f.room.city_code %></td>
<td><%= f.room.state_code %></td>
<td >
<input type="text" size="1" class="edit_position" value="<%= f.position %>" data-id='<%= f.id %>'></input>
</td>
<td><%= link_to "delete", manage_path(@subject, f), method: :delete %></td>
</tr>
<% end %>