Skip to main content

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)
NameTypeDefaultDescription
display_nameStringnilDisplay name of the page.
page_titleString | SymbolnilPage title. A symbol calls that method on the record.
page_descriptionStringnilText below the title. See Page header.
partialStringnilRender 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.