我想按数据库表列“plays”对其进行排序/排序(按我想要的方式降序或升序) 我完全糊涂了。刚刚找到了 select 而不是 collection_select 的解决方案?
我的一些代码
<%= f.collection_select :player1, Player.all, :id, :name %>
不知道如何排序/排序
数据库表中还有一些列,如“plays”、“goals”...
最佳答案
只需将实际排序的集合传递给 collection_select 助手:
collection_select(:post, :author_id, Author.order('created_at DESC'), :id, :name_with_initial, :prompt => true)
因此,在您的源代码示例中,它将如下所示:
<%= f.collection_select :player1, Player.order('plays DESC'), :id, :name %>
关于ruby-on-rails - ruby rails : How to sort a collection_select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596529/