Post creation

This commit is contained in:
Bat
2018-04-23 15:25:39 +01:00
parent 268607da0e
commit e506cd21b7
6 changed files with 92 additions and 0 deletions
+8
View File
@@ -39,4 +39,12 @@ impl Post {
.expect("Error loading post by id")
.into_iter().nth(0)
}
pub fn find_by_slug(conn: &PgConnection, slug: String) -> Option<Post> {
posts::table.filter(posts::slug.eq(slug))
.limit(1)
.load::<Post>(conn)
.expect("Error loading post by slug")
.into_iter().nth(0)
}
}