Show Page
cm_show configures the detail page of a record. Its content is organised in tabs, rows and sections.
Quick exampleβ
cm_show page_title: :title do
tab :profile, "" do
cm_section "Post Details" do
field :title
field :body, field_type: :rich_text
field :is_featured
field :status, field_type: :badge, badge_class: STATUS_TAG_COLOR
end
end
end
Optionsβ
cm_show(display_name: nil, page_title: nil, page_description: nil, partial: nil)
| Name | Type | Default | Description |
|---|---|---|---|
display_name | String | nil | Display name of the page. |
page_title | String | Symbol | nil | Page title. A symbol calls that method on the record. |
page_description | String | nil | Text below the title. See Page header. |
partial | String | nil | Render this partial instead of the default page. |
Recipesβ
Show associated records in a tabβ
cm_show page_title: :title do
tab :profile, "" do
cm_section "Details" do
field :title
end
end
tab :comments, "comment", associated_model: "comments", layout_type: "cm_association_index" do
column :message
end
end
A tab with an empty action name ("") is the main show tab. See tab for all options and Has One Tab for has_one associations.
A record-driven page titleβ
page_title accepts a symbol that is called on the record:
cm_show page_title: :user_full_name, page_description: "Leave request details" do
tab :profile, "" do
cm_section "Details" do
field :reason
end
end
end
Replace the whole page with a partialβ
partial renders your own view instead of the default layout β useful for previews or bespoke detail pages:
cm_show partial: "/cm_admin/blog_post/show"
Hide computed sections until they have dataβ
cm_section "Status Change Log", display_if: ->(record) { record.status_changes.any? } do
field :approved_by_name
field :approved_at, field_type: :date, format: "%d %b, %Y"
end
Add record-level actionsβ
custom_action inside cm_show puts a button on the record's page. This one opens a form modal:
cm_show page_title: :user_full_name do
custom_action name: "approve", route_type: "member", verb: "patch", path: ":id/approve",
display_type: :form_modal, icon_name: "fa-regular fa-circle-check",
display_if: ->(record) { record.pending? },
modal_configuration: { title: "Approve", confirmation_text: "Approve" } do
form do
cm_section "" do
form_field :approval_comment, input_type: :text
end
end
on_submit do
request = ::LeaveRequest.find(params[:id])
request.approve(params.dig(:leave_request, :approval_comment))
request
end
end
tab :profile, "" do
cm_section "Details" do
field :reason
end
end
end
See Custom actions for all display_types.
Relatedβ
- Show fields: every
fieldoption - Tabs, Rows and Sections
- Record history