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 })
| Name | Type | Default | Description |
|---|---|---|---|
display_name | String | "Delete" | Label of the Delete button. |
page_title | String | Symbol | nil | Modal title. A symbol calls that method on the record. |
page_description | String | nil | Modal text. |
confirmation_text | String | "Delete" | Label of the confirm button. |
partial | String | nil | Render this partial instead of the default modal. |
display_if | Proc | ->(_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? }
Relatedβ
- Views: remove
:destroyfromactionsto disable deletion entirely