Fix example

This commit is contained in:
Alex Kotov 2022-07-13 07:37:42 +03:00
parent 2caf37e455
commit d4d233526b
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 942 additions and 334 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,8 @@ edition = "2018"
publish = false
[dependencies]
rocket = "0.4.11"
rocket = "0.5.0-rc.2"
rocket_csrf = { path = "../.." }
rocket_contrib = { version = "0.4.11", features = ["handlebars_templates"] }
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["handlebars"] }
serde = "1.0.117"
serde_derive = "1.0.117"

View File

@ -5,10 +5,11 @@ extern crate rocket;
#[macro_use]
extern crate serde_derive;
use rocket::request::{FlashMessage, Form};
use rocket::form::Form;
use rocket::request::FlashMessage;
use rocket::response::{Flash, Redirect};
use rocket_contrib::templates::Template;
use rocket_csrf::CsrfToken;
use rocket_dyn_templates::Template;
#[derive(Serialize)]
struct TemplateContext {
@ -22,12 +23,12 @@ struct Comment {
text: String,
}
fn main() {
rocket::ignite()
#[launch]
fn rocket() -> _ {
rocket::build()
.attach(rocket_csrf::Fairing::default())
.attach(Template::fairing())
.mount("/", routes![index, new, create])
.launch();
}
#[get("/")]
@ -39,7 +40,7 @@ fn index() -> Redirect {
fn new(csrf_token: CsrfToken, flash: Option<FlashMessage>) -> Template {
let template_context = TemplateContext {
authenticity_token: csrf_token.authenticity_token().to_string(),
flash: flash.map(|msg| format!("{}! {}", msg.name(), msg.msg())),
flash: flash.map(|flash| flash.message().to_string()),
};
Template::render("comments/new", &template_context)