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.
6 7 8 9 10 11 12 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 6 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.
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 |
#extract_parameters(permitting) ⇒ Object
14 15 16 |
# File 'lib/dynamic_scaffold/form/item/cocoon.rb', line 14 def extract_parameters(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 |