From 39b5cb7f333906ee9c83d7adf62f1d60266b197f Mon Sep 17 00:00:00 2001 From: Sam Samai Date: Thu, 2 Sep 2021 22:30:23 +1000 Subject: [PATCH] Render flash messages --- examples/rocket_example/src/main.rs | 5 ++++- examples/rocket_example/static/css/style.css | 17 +++++++++-------- .../rocket_example/templates/index.html.tera | 5 +++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/rocket_example/src/main.rs b/examples/rocket_example/src/main.rs index c688ca99..7048e4d4 100644 --- a/examples/rocket_example/src/main.rs +++ b/examples/rocket_example/src/main.rs @@ -4,6 +4,7 @@ extern crate rocket; use rocket::fairing::{self, AdHoc}; use rocket::form::{Context, Form}; use rocket::fs::{relative, FileServer}; +use rocket::request::FlashMessage; use rocket::response::{Flash, Redirect}; use rocket::serde::json::Json; use rocket::{Build, Request, Rocket}; @@ -46,18 +47,20 @@ async fn create(conn: Connection, post_form: Form) -> Flash) -> Template { +async fn list(conn: Connection, flash: Option>) -> Template { let posts = Post::find() .all(&conn) .await .expect("could not retrieve posts") .into_iter() .collect::>(); + let flash = flash.map(FlashMessage::into_inner); Template::render( "index", context! { posts: posts, + flash: flash, }, ) } diff --git a/examples/rocket_example/static/css/style.css b/examples/rocket_example/static/css/style.css index cdf155ec..1b6a1720 100644 --- a/examples/rocket_example/static/css/style.css +++ b/examples/rocket_example/static/css/style.css @@ -2,24 +2,24 @@ border: 1px solid #ff0000 !important; } -.field-error-msg { +.field-error-flash { color: #ff0000; display: block; margin: -10px 0 10px 0; } .field-success { - border: 1px solid #5AB953 !important; + border: 1px solid #5ab953 !important; } -.field-success-msg { - color: #5AB953; +.field-success-flash { + color: #5ab953; display: block; margin: -10px 0 10px 0; } span.completed { - text-decoration: line-through; + text-decoration: line-through; } form.inline { @@ -29,7 +29,7 @@ form.inline { form.link, button.link { display: inline; - color: #1EAEDB; + color: #1eaedb; border: none; outline: none; background: none; @@ -45,8 +45,9 @@ button.link { letter-spacing: inherit; } -form.link:hover, button.link:hover { - color: #0FA0CE; +form.link:hover, +button.link:hover { + color: #0fa0ce; } button.small { diff --git a/examples/rocket_example/templates/index.html.tera b/examples/rocket_example/templates/index.html.tera index 2d74535c..077f7ff1 100644 --- a/examples/rocket_example/templates/index.html.tera +++ b/examples/rocket_example/templates/index.html.tera @@ -1,5 +1,10 @@ {% extends "base" %} {% block content %}

Posts

+{% if flash %} + + {{ flash.1 }} + +{% endif %}