Rails select_tag alphabetical order

html-select, ruby-on-rails

Solution

after a hour all you have to do is `.sort` the array of options that are passed into the options_for_select. this is my hack its a fix but not very sexy

select_tag :id, options_for_select(Portal.all.collect{|p| [p.name, portal_datum_path(p.id)]}.sort, [@portal.name, portal_datum_path(@portal)]), :onChange => "window.location=($(this).val());"

hope that helps

Problem

I have this `select_tag` ``` select_tag :id, options_for_select(Portal.all.collect{|p| [p.name, portal_datum_path(p.id)]}, [@portal.name, portal_datum_path(@portal)]), :onChange => "window.location=($(this).val());" ``` It allows a user to select a portal on which to see certain elements i want to display these portals in alphabetical order. I tried ordering the :name in the controller but no win. ``` def index @portals = Portal.with_name_or_subdomain(params[:keyword]).order(:name).limit(100) end ``` I looked at the rails docs there are no built in options within the select_tag itself is there some secret option that i should be using?

Original source