Class: ArrayInput

Inherits:
SimpleForm::Inputs::StringInput
  • Object
show all
Defined in:
app/inputs/array_input.rb

Overview

Instance Method Summary collapse

Instance Method Details

#input(_wrapper_options) ⇒ Object


5
6
7
8
9
10
11
12
13
14
# File 'app/inputs/array_input.rb', line 5

def input(_wrapper_options)
  input_html_options[:type] ||= input_type
  existing_values = Array(object.public_send(attribute_name)).map do |array_el|
    @builder.text_field(nil, input_html_options.merge(value: array_el, name: "#{object_name}[#{attribute_name}][]"))
  end
  if existing_values.empty?
    existing_values.push @builder.text_field(nil, input_html_options.merge(value: nil, name: "#{object_name}[#{attribute_name}][]"))
  end
  existing_values.join.html_safe
end

#input_typeObject


16
17
18
# File 'app/inputs/array_input.rb', line 16

def input_type
  :text
end