As pette is surely about to say when you query to get hotdesk order by code
@hotdesk = Hotdesk.order(:code)
문제
I have the following field in my form
<%=f.select(:desk, @hotdesk.collect {|p| [ p.code, p.code ] }, {prompt: 'Select Desk Code...'})%>
It works fine but the order of desk codes are all listed in terms of ID. How can I list them in order of their code (alphabetical)?
Thanks
해결책
As pette is surely about to say when you query to get hotdesk order by code
@hotdesk = Hotdesk.order(:code)
다른 팁
You could specify @hotdesk = Desk.order(code: :asc)
in your controller.
I am assuming Desk
as your model name and code
as your field. Replace them as per your model and field name.
If you want it in descending order then just specify desc
instead of asc
. By default ordering is ascending. So you can also do @hotdesk = Desk.order(code)
for ascending order.