New Page
cm_new configures the form used to create a record.
Quick exampleβ
cm_new page_title: "Add Post", page_description: "Enter all details to add Post" do
cm_section "Details" do
form_field :title, input_type: :string
form_field :body, input_type: :rich_text
end
end
Optionsβ
cm_new(display_name: "Add", page_title: nil, page_description: nil, partial: nil, redirect_to: nil, allow_create_action: -> { true })
| Name | Type | Default | Description |
|---|---|---|---|
display_name | String | "Add" | Label of the Add button. |
page_title | String | nil | Page title. |
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 created record; returns the URL to go to. |
allow_create_action | Proc | -> { true } | Lambda controlling whether the Add button is shown. |
Recipesβ
Redirect after createβ
cm_new display_name: "Add Post", redirect_to: ->(current_object) { "/pages/#{current_object.id}" } do
cm_section "Details" do
form_field :title
end
end
Split the form into stepsβ
cm_new page_title: "Add Post" do
step "Basic details" do
cm_section "Details" do
form_field :title, input_type: :string
end
end
step "Content" do
cm_section "Content" do
form_field :body, input_type: :rich_text
end
end
end
Steps are shown in declaration order with Back/Next navigation, and each step is validated on its own. The record is created after the final step. See Progressive Forms.
Relatedβ
- Form fields: every
form_fieldoption - Nested form fields
- Rows and Sections
- Edit page