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? link_to_remove_association(capture(&block), *args) elsif args.first.respond_to?(:object) form = args.first association = form.object.class.to_s.tableize name = I18n.translate("cocoon.#{association}.remove", default: I18n.translate('cocoon.defaults.remove')) link_to_remove_association(name, *args) else name, f, html_options = *args html_options ||= {} 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? f.hidden_field(:_destroy, value: f.object._destroy) + link_to(name, '#', html_options) end end