Edit Page
cm_edit configures the form used to update a record. It takes the same layout and fields as cm_new.
Quick exampleβ
cm_edit page_title: :title, page_description: "Enter all details to edit Post" do
cm_section "Details" do
form_field :title, input_type: :string
form_field :body, input_type: :rich_text
end
end
Optionsβ
cm_edit(display_name: "Edit", page_title: nil, page_description: nil, partial: nil, redirect_to: nil, display_if: ->(_arg) { true })
| Name | Type | Default | Description |
|---|---|---|---|
display_name | String | "Edit" | Label of the Edit button. |
page_title | String | Symbol | "Edit <Models>" | Page title. A symbol calls that method on the record. |
page_description | String | nil | Text below the title. |
partial | String | nil | Render this partial instead of the default form. |
redirect_to | Proc | nil | Lambda receiving the updated record; returns the URL to go to. |
display_if | Proc | ->(_arg) { true } | Lambda receiving the record; return false to hide the form. |
Recipesβ
Redirect after updateβ
cm_edit redirect_to: ->(current_object) { "/pages/#{current_object.id}" } do
cm_section "Details" do
form_field :title
end
end
Split the form into stepsβ
Use step blocks exactly as in cm_new. The record is updated only when the final step is saved. See Progressive Forms.