Skip to main content

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 })
NameTypeDefaultDescription
display_nameString"Edit"Label of the Edit button.
page_titleString | Symbol"Edit <Models>"Page title. A symbol calls that method on the record.
page_descriptionStringnilText below the title.
partialStringnilRender this partial instead of the default form.
redirect_toProcnilLambda receiving the updated record; returns the URL to go to.
display_ifProc->(_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.