Skip to content

Commit

Permalink
Allow managed models to be ActiveModels (as suggested in nathanvda/co…
Browse files Browse the repository at this point in the history
  • Loading branch information
gael-ian committed Mar 7, 2023
1 parent bc2fe3f commit 6f2d073
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/cocooned/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ def cocooned_remove_item_link(name, form = nil, html_options = {}, &block)
association = form.object.class.to_s.tableize
return cocooned_remove_item_link(cocooned_default_label(:remove, association), form, html_options) if name.nil?

destroy = form.object.respond_to?(:marked_for_destruction?) && form.object.marked_for_destruction?

link_options = html_options.dup
link_options[:class] = [html_options[:class], Cocooned::HELPER_CLASSES[:remove]].flatten.compact
link_options[:class] << (form.object.new_record? ? 'dynamic' : 'existing')
link_options[:class] << 'destroyed' if form.object.marked_for_destruction?
link_options[:class] << (form.object.respond_to?(:new_record?) && form.object.new_record? ? :dynamic : :existing)
link_options[:class] << :destroyed if destroy.present?

form.hidden_field(:_destroy, value: form.object._destroy) << link_to(name, '#', link_options)
form.hidden_field(:_destroy, value: destroy) << link_to(name, '#', link_options)
end

# Output an action link to move an item up.
Expand Down

0 comments on commit 6f2d073

Please sign in to comment.