Skip to main content

Delete

cm_destroy configures the confirmation modal shown before a record is deleted.

Quick example​

cm_destroy display_name: "Delete Post", confirmation_text: "Delete", page_title: "Delete Post",
page_description: "Are you sure you want to delete this Post?"

Options​

cm_destroy(display_name: "Delete", page_title: nil, page_description: nil, confirmation_text: "Delete", partial: nil, display_if: ->(_arg) { true })
NameTypeDefaultDescription
display_nameString"Delete"Label of the Delete button.
page_titleString | SymbolnilModal title. A symbol calls that method on the record.
page_descriptionStringnilModal text.
confirmation_textString"Delete"Label of the confirm button.
partialStringnilRender this partial instead of the default modal.
display_ifProc->(_arg) { true }Lambda receiving the record; return false to hide Delete.

Without a cm_destroy call the modal uses the title Delete <Model> and the text Are you sure you want to delete this <Model>?. Calling cm_destroy replaces both with the values you pass, so set page_title and page_description when you use it.

Recipes​

Only allow deleting drafts​

cm_destroy display_if: ->(post) { post.draft? }
  • Views: remove :destroy from actions to disable deletion entirely