I have the following line of code
<% map = options_for_select(User.all.map {|u| [u.first_name+" "+u.last_name, u.id]}) %>
which grabs the first and last name of a user and submits its ID in a form. Now I have added a few users and they are not in alphabetical order. How can I sort this map by first name?
You can also use order to get the rows already ordered from the database:
<% map = options_for_select(User.all.order(:first_name).map {|u| [u.first_name+" "+u.last_name, u.id]}) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With