module Cocoon::ViewHelpers
Public Instance Methods
link_to_remove_association(*args, &block)
click to toggle source
this will show a link to remove the current association. This should be placed inside the partial. either you give
-
name : the text of the link
-
f : the form this link should be placed in
-
html_options: html options to be passed to link_to (see
link_to
)
or you use the form without name with a *&block*
-
f : the form this link should be placed in
-
html_options: html options to be passed to link_to (see
link_to
) -
*&block*: the output of the block will be show in the link, see
link_to
# File lib/cocoon/view_helpers.rb, line 16 def link_to_remove_association(*args, &block) if block_given? f = args.first html_options = args.second || {} name = capture(&block) link_to_remove_association(name, f, html_options) else name = args[0] f = args[1] html_options = args[2] || {} is_dynamic = f.object.new_record? classes = [] classes << "remove_fields" classes << (is_dynamic ? 'dynamic' : 'existing') classes << 'destroyed' if f.object.marked_for_destruction? html_options[:class] = [html_options[:class], classes.join(' ')].compact.join(' ') wrapper_class = html_options.delete(:wrapper_class) html_options[:'data-wrapper-class'] = wrapper_class if wrapper_class.present? hidden_field_tag("#{f.object_name}[_destroy]", f.object._destroy) + link_to(name, '#', html_options) end end