Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Includes:
SimpleForm::ActionViewExtensions::Builder
Defined in:
lib/simple_form/action_view_extensions/builder.rb

Direct Known Subclasses

SimpleForm::FormBuilder

Instance Method Summary collapse

Methods included from SimpleForm::ActionViewExtensions::Builder

#collection_check_boxes, #collection_radio, #simple_fields_for

Instance Method Details

#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/simple_form/action_view_extensions/builder.rb', line 170

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)
      [value, text]
    end
    value_method, text_method = :first, :last
  end

  original_collection_select(attribute, collection, value_method, text_method, options, html_options)
end

#original_collection_selectObject

Override default Rails collection_select helper to handle lambdas/procs in text and value methods, so it works the same way as collection_radio 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.



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

alias :original_collection_select :collection_select