Created
January 8, 2011 01:38
-
-
Save topgenorth/770419 to your computer and use it in GitHub Desktop.
should get a list of publishers, sort them by display name, and create a select with a default value as the first option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sorted_publishers_select_tag(default_option = nil) | |
publishers = Publisher.accessible_by(current_user.ability) | |
publishers.sort!{ |a,b| a.display_name.downcase <=> b.display_name.downcase } | |
options_tag = options_from_collection_for_select(publishers, 'id', 'display_name', params[:publisher_id]) | |
if default_option.nil? | |
options = {} | |
else | |
# after sorting we need to stick in the default value so it's at the top | |
options = {:include_blank => default_option } | |
end | |
content_tag :select, options_tag, {"name" => 'publisher_id', "id" => 'publisher_id'}.update(options.stringify_keys) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment