문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top