Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/simple_form/action_view_extensions/builder.rb

Instance Method Summary collapse

Instance Method Details

#options_from_collection_for_select(collection, value_method, text_method, selected = nil) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/simple_form/action_view_extensions/builder.rb', line 291

def options_from_collection_for_select(collection, value_method, text_method, selected = nil)
  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)

      [value, text]
    end

    value_method, text_method = :first, :last
    selected = extract_selected_and_disabled_and_call_procs selected, collection
  end

  original_options_from_collection_for_select collection, value_method, text_method, selected
end

#original_options_from_collection_for_selectObject

Override Rails options_from_collection_for_select 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. FIXME: remove when support only Rails 4.0 forward

https://github.com/rails/rails/commit/9035324367526af0300477a58b6d3efc15d1a5a8


290
# File 'lib/simple_form/action_view_extensions/builder.rb', line 290

alias :original_options_from_collection_for_select :options_from_collection_for_select