diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2017-11-16 17:15:06 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2017-11-16 17:15:06 +0100 |
commit | 114b777b806f793ebfe21895830bae99f524c9d5 (patch) | |
tree | c6de884ccebe8da4d071d3d6bf5ba6c0d17e09b3 /src | |
parent | 3bc7143ced57da953969d80d99ff8466ab986ae2 (diff) | |
download | rocket-blog-114b777b806f793ebfe21895830bae99f524c9d5.tar.gz rocket-blog-114b777b806f793ebfe21895830bae99f524c9d5.tar.bz2 rocket-blog-114b777b806f793ebfe21895830bae99f524c9d5.zip |
Pass posts to the template and iterate over them.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 8dd6771..55131fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use self::rocket_blog::{schema, models}; #[template = "templates/index.html"] struct IndexTemplate<'a> { title: &'a str, - content: &'a str + posts: Vec<models::Post> } #[get("/")] @@ -24,11 +24,7 @@ fn index(conn: rocket_blog::DbConn) -> String { .load::<models::Post>(&*conn) .expect("Error loading posts"); - let output : String = results.iter().map(|post| { - format!("{}", &IndexTemplate{ title: &post.title, content: &post.body }) - }).collect(); - - output + format!("{}", &IndexTemplate{ title: "Bloggen", posts: results }) } fn main() { |