Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Includes:
- Select7::TagHelper
- Defined in:
- app/helpers/select7/form_helper.rb
Instance Method Summary collapse
Methods included from Select7::TagHelper
#select7_item_tag, #select7_tag
Instance Method Details
#select7(options: [], selecteds: [], suggest: {}, multiple: true, params: @template.params, **attributes) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/select7/form_helper.rb', line 5 def select7(options: [], selecteds: [], suggest: {}, multiple: true, params: @template.params, **attributes) field, (value_attr, text_attr) = attributes.first input_name = if scope = @object_name then "#{scope}[#{field.to_s.singularize}_#{value_attr}#{multiple ? 's' : ''}]" + (multiple ? "[]" : "") else "#{field.to_s.singularize}_#{value_attr}" + (multiple ? "s[]" : "") end selecteds = (if @object then @object.send(field) else clazz = field.to_s.classify.constantize Array(clazz.where(value_attr.to_sym => params["#{field.to_s.singularize}_#{value_attr}s"]).all) end).map { |item| [item.send(value_attr), item.send(text_attr)] } select7_tag( **attributes, options: , selecteds: selecteds, suggest: suggest, scope: @object_name, input_name: input_name, ) end |