Question

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

Was it helpful?

Solution

As pette is surely about to say when you query to get hotdesk order by code

@hotdesk = Hotdesk.order(:code)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top