开发者

Ruby on Rails: How to sort a collection_select

开发者 https://www.devze.com 2023-03-17 21:54 出处:网络
I want to sort / order it (desc or asc how i want it) by the database table column \"plays\" Im totally confused. Just found a solution for select but not collection_select?

I want to sort / order it (desc or asc how i want it) by the database table column "plays" Im totally confused. Just found a solution for select but not collection_select?

some code of my view

<%= f.collection_select :player1, Player.all, :id, :name %>

dont know how to sort / order

there are also col开发者_如何转开发umns in the database table like "plays", "goals" ...


Just pass actually ordered collection to collection_select helper:

collection_select(:post, :author_id, Author.order('created_at DESC'), :id, :name_with_initial, :prompt => true)

So, in your source example it will look like this:

<%= f.collection_select :player1, Player.order('plays DESC'), :id, :name %>
0

精彩评论

暂无评论...
验证码 换一张
取 消