I am trying to build a select box that will return my list of projects in alphabetic order:
<%= f.select(:project_id, current_user.projects.all(:order => 'name').collect {|p| [ p.name, p.id ]}) %>
This works as long as the name field contains only one word, e.g. Project.
All entries containing blanks, e.g. My project, will not be ordered though. They simply appear at the top of the list.
How can I order all of the strings?
Thanks for any help.
OK, this is what I ended up with:
Seems like the uppercase entries were causing the problem. The *sort_by* method comes to the rescue. Not sure if there’s a better way to do this, though.