Skip to main content

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 })
NameTypeDefaultDescription
display_nameString"Add"Label of the Add button.
page_titleStringnilPage title.
page_descriptionStringnilText below the title.
partialStringnilRender this partial instead of the default form.
redirect_toProcnilLambda receiving the created record; returns the URL to go to.
allow_create_actionProc-> { 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.