Class: DynamicScaffold::Form::Item::Cocoon
- Inherits:
-
Base
- Object
- Base
- DynamicScaffold::Form::Item::Cocoon
show all
- Defined in:
- lib/dynamic_scaffold/form/item/cocoon.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#name, #parent_item
Instance Method Summary
collapse
Methods inherited from Base
create, #default, #default_value, #errors, #if, #insert, #label, #label?, #needs_rendering?, #note, #notes?, #proxy, #proxy_field, #render_label, #render_notes, #type?, #unique_name, #unless
Constructor Details
#initialize(config, type, name, options = {}) {|@form| ... } ⇒ Cocoon
Returns a new instance of Cocoon.
6
7
8
9
10
11
12
|
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 6
def initialize(config, type, name, options = {})
super
@options = options
@form = FormBuilder.new(config)
@form.parent_item = self
yield(@form)
end
|
Instance Attribute Details
Returns the value of attribute form.
5
6
7
|
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 5
def form
@form
end
|
Instance Method Details
#add_text ⇒ Object
23
24
25
|
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 23
def add_text
@options[:add_text] || "Add #{proxy_field.label}"
end
|
#build_children(record) ⇒ Object
27
28
29
30
31
|
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 27
def build_children(record)
children = record.public_send(name).to_a
children = @filter.call(children) if @filter.present?
children
end
|
14
15
16
|
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 14
def (permitting)
permitting << { "#{@name}_attributes": [*@form.items.map(&:name).push(:_destroy)] }
end
|
#filter(&block) ⇒ Object
18
19
20
21
|
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 18
def filter(&block)
@filter = block
self
end
|