Class: JsonFields::ArraySimpleStructure
- Inherits:
-
BaseStructure
- Object
- BaseStructure
- JsonFields::ArraySimpleStructure
- Defined in:
- lib/json_fields/array_simple_structure.rb
Instance Attribute Summary
Attributes inherited from BaseStructure
Instance Method Summary collapse
-
#assemble(values) ⇒ Object
Takes in values and returns a normal structure that can be saved.
-
#template(object_name, method, options) ⇒ Object
‘object_name` is a String snake_case name of the object `method` is a Symbol of the method being called `options` is a Hash.
Methods inherited from BaseStructure
Constructor Details
This class inherits a constructor from JsonFields::BaseStructure
Instance Method Details
#assemble(values) ⇒ Object
Takes in values and returns a normal structure that can be saved
27 28 29 30 31 32 33 |
# File 'lib/json_fields/array_simple_structure.rb', line 27 def assemble(values) if allow_blank values else values.delete_if(&:blank?) end end |
#template(object_name, method, options) ⇒ Object
‘object_name` is a String snake_case name of the object `method` is a Symbol of the method being called `options` is a Hash. `options` contains the instance of the object returns the HTML template to be used
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/json_fields/array_simple_structure.rb', line 8 def template(object_name, method, ) obj = [:object] id = [object_name, method, 'json_field'].join('_') content_tag(:div, id: id) do html = content_tag(:a, 'Add Field', href: '#', class: 'btn btn-add add-json-fields', 'data-target' => id) (Array(obj.send(method)) + [""]).collect.with_index { |value, idx| html += content_tag(:div, class: ['template', .delete(:wrapper_class)].compact.join(' ')) do [text_field_tag("#{object_name}[#{method}][]", nil, value: value, class: 'json-field-control', id: nil, name: "#{object_name}[#{method}][]"), content_tag(:a, '-', href: '#', class: 'btn btn-remove remove-json-fields') ].join.html_safe end } html.html_safe end end |