Example: Simple Blog
A complete working blog on web pages: a list page, a post page with its own URL per post, an editor section with a publishing flow, live search and a JSON feed.
One post document holds everything a list shows
{
"_meta": {
"cms": 1782080295147,
"created": 1782080295,
"entity": 1,
"expiry": -1,
"guid": "a23575f49d0af385314c1f02280163374297e018a692e5e4ab85eb307ebf6ebc",
"removed": 0,
"ums": 1782166695813,
"update_hash": "60e27209fa93063b5605e41605c2722ed428cae0",
"updated": 1782166695
},
"author_guid": "a23575f49d0af385314c1f02280163374297e018a692e5e4ab85eb307ebf6ebc",
"author_name": "sami b",
"body": "Why we rebuilt\n\nEverything starts with...",
"published_at": 1782166695,
"slug": "why-we-rebuilt-the-docs",
"status": "published",
"tags": [
"docs",
"meta"
],
"title": "why we rebuilt the docs"
}One posts storage, everything embedded: the author is denormalized (author_name stored next to author_guid) so list pages never join. That is the core storage principle from Storages.
Two public pages and a feed share one query
The list page
Add the page
web_page(new web page) witheventblogand scope*public.Query the posts
function_search(search) withquery_bool_term_fields(fields) onstatus=publishedinquery_bool_filter(filter), andquery_sort_field(sorting) onpublished_atdescending, merged byquery_and(multiple), withlimit20.Render the rows
Wire
arrayintoweb_foreach(web for each) with the row template below, and set itsemptypin to<p>No posts yet.</p>.Render the page
web_render(web render) withtitle,descriptionand a custom pinpostsholding thehtmlofweb_foreach. Setcache secondsto let shared caches keep it.
<article>
<h2><a href="/blog/{{slug}}">{{title | capitalize}}</a></h2>
<p>{{author_name}}, {{published_at | date "DD-MM-YYYY"}}</p>
<p>{{body | truncate 160}}</p>
</article><main class="blog">
<h1>{{title}}</h1>
<input name="q" type="search" placeholder="Search posts"
data-action="search" data-trigger="input" data-debounce="300">
<div id="posts">{{{posts}}}</div>
</main>The post page
Give every post a URL
web_pagewitheventblog/:slugand scope*public. Readslugfrom itsparamspin withobject_field_getter_multiple(get fields).Fetch it
function_search_single_result(search single) with a term onslugand a term onstatus=published, so drafts 404 for the public.Answer both paths
branch(branch) onhas_hits. True:web_renderwith a custom pinpost,titlefrom the post, andjson_ldif you want structured data. False:web_renderwithstatus404and a short not-found template.
<article>
<h1>{{post.title | capitalize}}</h1>
<p>{{post.author_name}}, {{post.published_at | date "DD-MM-YYYY"}}</p>
<p>{{post.body | nl2br}}</p>
<ul>
{{for tag in post.tags}}
<li>{{tag}}</li>
{{/for}}
</ul>
</article>The feed
The same list query behind on_startup_register_uri_get (On API GET), answered with httpconnection_set_json (reply in JSON), gives external readers JSON. See Creating a REST API.
Publishing is a status change on an editor page
Put the editor pages in a blueprint of their own, with a custom scope such as editor. An action without scopes of its own requires what every page of its blueprint requires, so this keeps public reads and editor writes cleanly apart.
List everything
web_pagewitheventblog-admin, the same search without the status filter, andweb_foreachwith the stored row template{{> post-admin-row}}. Rows are keyed by the document's guid.Write drafts
A form with
data-action="save-post"runsweb_action(on web action)save-post. Build the slug once from the title withvalue_to_lowercase(convert to lowercase) andvalue_replace(replace) (/[^a-z0-9]+/gto-). Create withfunction_create_document_from_mutations(create document), using the slug asguid_seedandstatus: draft.Refuse a duplicate
A slug that already exists makes that block answer
successfalse withDOCUMENT_GUID_ALREADY_EXISTS. Answer withweb_errors(web form errors) on the title field. On success,web_redirect(web redirect) back to/blog-admin.Publish in place
The row's button runs
web_actionpublish. Itskeypin is the document's guid:function_update_document_mutations(update document) setsstatus: publishedandpublished_at,web_template(web template) renders{{> post-admin-row}}with the updatedobjectasdataand the guid askey, andweb_replace(web replace) swaps that one row.
<tr>
<td>{{title | capitalize}}</td>
<td>{{status}}</td>
<td>
<a href="/blog-admin/edit/{{_meta.guid}}">Edit</a>
{{if status == 'draft'}}
<button type="button" data-action="publish" data-loading-text="Publishing">Publish</button>
{{/if}}
</td>
</tr>Edits create revisions automatically, and the public list only ever shows published.
Search runs while the visitor types
The input on the list page runs an action named search 300 ms after typing stops; a request still running is cancelled.
Read the term
web_actionsearch; the term isqon itsformpin. Lowercase it withvalue_to_lowercase.Search
Feed
query_bool_simple_query_string_field(simple query string) ontitleandbodyintoquery_bool_must(must), merged with the same published filter and sort. Lowercase those fields at write time, per search optimization.Answer with the rows
web_foreachwith the same row template, andweb_update(web update) withtarget#postsand itshtml.
What to reuse
- One storage per content type; embed what lists display.
- Status fields drive visibility. Never delete content, transition it.
- Public reads and editor writes are separate pages with separate scopes.
- The same query serves the page, the API and the search box.
Next steps
Lists and Tables Rows, keys and empty states with web_foreach. SEO and Sharing The head tags, Open Graph and structured data a post gets. Storage Examples More production-shaped data models. E-Commerce Catalog The same pattern at product scale.Frequently asked
How do I keep draft blog posts out of the public list in RUAL?
Drive visibility with a status field. The public pages query status = published, and the post page adds a term on status so drafts return 404 for the public. Publishing is a mutation from draft to published plus a published_at timestamp: never delete content, transition it.
Why does the RUAL blog example store the author name on every post?
RUAL storage has no joins, so the author is denormalized: author_name is stored next to author_guid, and list pages render names without fetching a second document.
How do I add a search box to a RUAL blog?
Feed query_bool_simple_query_string_field on title and body into the same list query that serves the index page, and store those fields in lowercase at write time so the case-sensitive search matches.