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?
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
alter it to
select_tag :id, options_from_collection_for_select(portals,:name, :id, 1), :onChange => "window.location=($(this).val());"**strong text**
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