Class: Para::Inputs::NestedManyInput
- Inherits:
-
NestedBaseInput
- Object
- SimpleForm::Inputs::Base
- NestedBaseInput
- Para::Inputs::NestedManyInput
- Defined in:
- lib/para/inputs/nested_many_input.rb
Constant Summary
Constants inherited from NestedBaseInput
Para::Inputs::NestedBaseInput::GLOBAL_NESTED_FIELD_KEY
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #input(wrapper_options = nil) ⇒ Object
- #inset? ⇒ Boolean
- #model ⇒ Object
- #parent_model ⇒ Object
- #remote_partial_params ⇒ Object
- #render_partial? ⇒ Boolean
- #uncollapsed? ⇒ Boolean
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/para/inputs/nested_many_input.rb', line 4 def resource @resource end |
Instance Method Details
#input(wrapper_options = nil) ⇒ Object
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 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/para/inputs/nested_many_input.rb', line 6 def input( = nil) [:class] << "nested-many" orderable = .fetch(:orderable, model.orderable?) = .fetch(:add_button, true) # Load existing resources resources = object.send(attribute_name) # Order them if the list should be orderable resources = resources.sort_by(&:position) if orderable locals = .fetch(:locals, {}) with_global_nested_field do template.render( partial: 'para/inputs/nested_many', locals: { form: @builder, model: model, attribute_name: attribute_name, orderable: orderable, add_button: , dom_identifier: dom_identifier, resources: resources, nested_locals: locals, subclass: subclass, subclasses: subclasses, add_button_label: , add_button_class: , inset: inset?, uncollapsed: uncollapsed?, render_partial: render_partial?, remote_partial_params: remote_partial_params } ) end end |
#inset? ⇒ Boolean
51 52 53 |
# File 'lib/para/inputs/nested_many_input.rb', line 51 def inset? .fetch(:inset, false) end |
#model ⇒ Object
47 48 49 |
# File 'lib/para/inputs/nested_many_input.rb', line 47 def model @model ||= parent_model.reflect_on_association(attribute_name).klass end |
#parent_model ⇒ Object
43 44 45 |
# File 'lib/para/inputs/nested_many_input.rb', line 43 def parent_model @parent_model ||= @builder.object.class end |
#remote_partial_params ⇒ Object
63 64 65 66 67 |
# File 'lib/para/inputs/nested_many_input.rb', line 63 def remote_partial_params @remote_partial_params ||= .fetch(:remote_partial_params, {}).merge( namespace: :nested_form ) end |
#render_partial? ⇒ Boolean
59 60 61 |
# File 'lib/para/inputs/nested_many_input.rb', line 59 def render_partial? [:render_partial] || object.errors.any? || (object.persisted? && uncollapsed?) end |