Scaffold

Scaffolding is an efficient and speedy method for generating key components of an application. By utilizing scaffolding, you can create models, views, and controllers for a new resource all in one go.

See scaffold command:

Generates a CRUD scaffold, model and controller

Usage: blo-cli generate scaffold [OPTIONS] <NAME> [FIELDS]...

Arguments:
  <NAME>       Name of the thing to generate
  [FIELDS]...  Model fields, eg. title:string hits:int

Options:
  -k, --kind <KIND>                The kind of scaffold to generate [default: api] [possible values: api, html, htmx]
  -e, --environment <ENVIRONMENT>  Specify the environment [default: development]
  -h, --help                       Print help
  -V, --version                    Print version

You can begin by generating a scaffold for the Post resource, which will represent a single blog posting. To accomplish this, open your terminal and enter the following command:

cargo loco generate scaffold posts name:string title:string content:text

The scaffold generate command support API, HTML or HTMX by adding --template flag to scaffold command.

The scaffold generator will build several files in your application:

FilePurpose
migration/src/lib.rsInclude Post migration.
migration/src/m20240606_102031_posts.rsPosts migration.
src/app.rsAdding Posts to application router.
src/controllers/mod.rsInclude the Posts controller.
src/controllers/posts.rsThe Posts controller.
tests/requests/posts.rsFunctional testing.
src/models/mod.rsIncluding Posts model.
src/models/posts.rsPosts model,
src/models/_entities/mod.rsIncludes Posts Sea-orm entity model.
src/models/_entities/posts.rsSea-orm entity model.
src/views/mod.rsIncluding Posts views. only for HTML and HTMX templates.
src/views/posts.rsPosts template generator. only for HTML and HTMX templates.
assets/views/posts/create.htmlCreate post template. only for HTML and HTMX templates.
assets/views/posts/edit.htmlEdit post template. only for HTML and HTMX templates.
assets/views/posts/edit.htmlEdit post template. only for HTML and HTMX templates.
assets/views/posts/list.htmlList post template. only for HTML and HTMX templates.
assets/views/posts/show.htmlShow post template. only for HTML and HTMX templates.