Module: ApplicationCocoonHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/application_cocoon_helper.rb

Instance Method Summary collapse

Instance Method Details

Shows a link that will allow to dynamically add a new associated object. This is a wrapper of

link_to_add_association

Overloads:

  • #link_to_add_association(name, form, options, association, html_options = nil) ⇒ String

    Shows a link that will allow to dynamically add a new associated object.

    Examples:

    Adding items after the link

    link_to_add_association(t('.add_option'), f, :options, find_selector: 'this',
                                                           insert_using: 'after')

    Options Hash (html_options):

    • :find_using (String)

      The jQuery traversal method to allow node selection relative to the link. Example values: +this+, +closest+, +next+, +children+, etc. Default: absolute selection.

    • :selector (String)

      The jQuery selector to be used with +:find_using+ to determine where to insert the new node. Default: the parent node.

    • :find_selector (String)

      The alias of +:selector+, you should use this when +:find_using+ is not specified. Default: parent node.

    • :insert_using (String) — default: 'before'

      The jQuery method that inserts the new data. Example values: +before+, +after+, +append+, +prepend+, etc.

  • #link_to_add_association(form, options, association, html_options = nil, &block) ⇒ String

    Shows a link that will allow to dynamically add a new associated object. The display of the link can be changed in the block.

    Options Hash (html_options):

    • :find_using (String)

      The jQuery traversal method to allow node selection relative to the link. Example values: +this+, +closest+, +next+, +children+, etc. Default: absolute selection.

    • :selector (String)

      The jQuery selector to be used with +:find_using+ to determine where to insert the new node. Default: the parent node.

    • :find_selector (String)

      The alias of +:selector+, you should use this when +:find_using+ is not specified.

    • :insert_using (String) — default: 'before'

      The jQuery method that inserts the new data. Example values: +before+, +after+, +append+, +prepend+, etc.


47
48
49
50
51
52
# File 'app/helpers/application_cocoon_helper.rb', line 47

def link_to_add_association(name, form, association = nil, html_options = nil, &block)
  name, form, association, html_options = nil, name, form, association if block_given?
  html_options = html_options&.dup || {}
  replace_cocoon_keys(html_options)
  super(*[name, form, association, html_options].compact, &block)
end