# File lib/simple_form/action_view_extensions/builder.rb, line 287 def collection_select(attribute, collection, value_method, text_method, options={}, html_options={}) if value_method.respond_to?(:call) || text_method.respond_to?(:call) collection = collection.map do |item| value = value_for_collection(item, value_method) text = value_for_collection(item, text_method) default_html_options = default_html_options_for_collection(item, value, options, html_options) disabled = value if default_html_options[:disabled] selected = value if default_html_options[:selected] [value, text, selected, disabled] end [:disabled, :selected].each do |option| option_value = collection.map(&:pop).compact options[option] = option_value if option_value.present? end value_method, text_method = :first, :last end original_collection_select(attribute, collection, value_method, text_method, options, html_options) end
Override default Rails #collection_select helper to handle lambdas/procs in text and value methods, so it works the same way as collection_radio_buttons and collection_check_boxes in SimpleForm. If none of text/value methods is a callable object, then it just delegates back to original collection select.