Class: DynamicScaffold::Form::Item::Cocoon
- Defined in:
- lib/dynamic_scaffold/form/item/cocoon.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Attributes inherited from Base
#multiple, #name, #parent_item
Instance Method Summary collapse
- #add_text ⇒ Object
- #build_children(record) ⇒ Object
- #extract_parameters(permitting) ⇒ Object
- #filter(&block) ⇒ Object
-
#initialize(config, type, name, options = {}) {|@form| ... } ⇒ Cocoon
constructor
A new instance of Cocoon.
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.
8 9 10 11 12 13 14 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 8 def initialize(config, type, name, = {}) super @options = @form = FormBuilder.new(config) @form.parent_item = self yield(@form) end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
7 8 9 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 7 def form @form end |
Instance Method Details
#add_text ⇒ Object
25 26 27 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 25 def add_text @options[:add_text] || "Add #{proxy_field.label}" end |
#build_children(record) ⇒ Object
29 30 31 32 33 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 29 def build_children(record) children = record.public_send(name).to_a children = @filter.call(children) if @filter.present? children end |
#extract_parameters(permitting) ⇒ Object
16 17 18 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 16 def extract_parameters(permitting) permitting << { "#{@name}_attributes": [*@form.items.map(&:name).push(:_destroy)] } end |
#filter(&block) ⇒ Object
20 21 22 23 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 20 def filter(&block) @filter = block self end |