Views
Every model you register gets a set of pages: an index listing, a show page and new/edit/delete forms. You declare them in a cm_admin block, usually in a concern under app/models/concerns/cm_admin/.
Quick exampleβ
app/models/concerns/cm_admin/blog_post.rb
module CmAdmin
module BlogPost
extend ActiveSupport::Concern
included do
cm_admin do
actions only: %i[index show new create edit update destroy history]
icon_name "fa-solid fa-newspaper"
cm_index do
column :title
end
cm_show do
tab :profile, "" do
cm_section "Details" do
field :title
end
end
end
end
end
end
end
app/models/blog_post.rb
class BlogPost < ApplicationRecord
has_paper_trail
include CmAdmin::BlogPost
end
Then add BlogPost to config.included_models in config/initializers/cm_admin.rb. Its pages are served under /admin/blog_posts.
Model settingsβ
Call these directly inside cm_admin do ... end.
| Method | Default | Description |
|---|---|---|
actions | all default actions | actions only: [...] or actions except: [...]. See Default actions. |
icon_name | "fa fa-th-large" | Font Awesome icon shown in the sidebar. |
display_name | Model name, titleized | Name shown in the sidebar. |
visible_on_sidebar | true | Set false to hide the model from the sidebar and global search while keeping its pages. |
description | nil | Model description returned to AI clients by the MCP server. |
policy_scopes | [Full Access] | Extra permission scopes. See Roles & Permissions. |
comments_tab | none | Adds a comments tab. See Comments & Mentions. |
global_search_fields | none | Fields searched by Global Search. |
Default actionsβ
| Action | Route | Page |
|---|---|---|
index | GET / | Index page |
show | GET /:id | Show page |
new / create | GET /new, POST / | New page |
edit / update | GET /:id/edit, PATCH /:id | Edit page |
destroy | DELETE /:id | Delete |
history | GET /:id/history | Record history. Needs has_paper_trail on the model (Auditing). |
export | POST /export_to_file | CSV/XLSX export from the index page. |
warning
Listing :history in actions only: on a model without has_paper_trail raises at boot in development and test, and logs a warning elsewhere.
Page headerβ
These work inside any view block (cm_index, cm_show, cm_new, β¦).
| Method | Arguments | Description |
|---|---|---|
page_title | title | Page title. |
page_description | description | Shown below the title. Accepts HTML (formatting, lists, links); media is stripped, links open in a new tab, and long text is clamped to two lines with View more / View less. |
title_icon | icon_name:, url:, tooltip: nil, display_if: nil | Icon button next to the title linking to url in a new tab. Renders only when both icon_name and url are set. |
cm_index do
page_title "Posts"
page_description "<p>All posts. <strong>Drafts</strong> are only visible to editors.</p>"
title_icon icon_name: "fa-solid fa-circle-info", url: "https://example.com/tutorial", tooltip: "Click to view tutorial"
end
Relatedβ
- Tabs, Rows and Sections
- Columns, Show fields and Form fields
- Custom actions