Module: Select7::TagHelper

Included in:
ActionView::Helpers::FormBuilder
Defined in:
app/helpers/select7/tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#select7_item_tag(id, content = nil) ⇒ Object



22
23
24
# File 'app/helpers/select7/tag_helper.rb', line 22

def select7_item_tag(id, content = nil)
    render partial: "select7/item", locals: {id: id, content: content || yield.html_safe }
end

#select7_tag(options: [], selecteds: [], suggest: {}, **attributes) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/select7/tag_helper.rb', line 2

def select7_tag(options: [], selecteds: [], suggest: {}, **attributes)
    field, (value_attr, text_attr) = attributes.first
    options_for_select = options.map { |item| 
        [item.send(value_attr), item.send(text_attr), item.send(text_attr).downcase] 
    }
    attributes.reverse_merge!(css: {}, multiple: true, nested_attributes: nil)
    attributes[:input_name] ||= "#{field.to_s.singularize}_#{value_attr}"

    (@template || self).render partial: "select7/field", 
        locals: { 
            field: field,
            value_attr: value_attr,
            text_attr: text_attr,
            selected_items: selecteds, 
            option_items: options_for_select, 
            suggest: suggest || {}, 
            **attributes 
        }
end