tutorials: fix index() (#5732)
parent
246e7e8464
commit
317b2dc579
|
@ -64,7 +64,7 @@ fn main() {
|
||||||
vweb.run<App>(8081)
|
vweb.run<App>(8081)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut app App) index() vweb.Result {
|
pub fn (mut app App) index() vweb.Result {
|
||||||
app.vweb.text('Hello, world from vweb!')
|
app.vweb.text('Hello, world from vweb!')
|
||||||
return vweb.Result{}
|
return vweb.Result{}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ Let's return an HTML view instead. Create `index.html` in the same directory:
|
||||||
and update our `index()` action so that it returns the HTML view we just created:
|
and update our `index()` action so that it returns the HTML view we just created:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
fn (mut app App) index() vweb.Result {
|
pub fn (mut app App) index() vweb.Result {
|
||||||
message := 'Hello, world from Vweb!'
|
message := 'Hello, world from Vweb!'
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ We'll be using V's builtin ORM and a SQLite database.
|
||||||
|
|
||||||
Create a SQLite file with the schema:
|
Create a SQLite file with the schema:
|
||||||
```sql
|
```sql
|
||||||
drop table Article;
|
drop table if exists Article;
|
||||||
|
|
||||||
create table Article (
|
create table Article (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
|
@ -252,7 +252,7 @@ pub fn (app &App) find_all_articles() []Article {
|
||||||
Let's fetch the articles in the `index()` action:
|
Let's fetch the articles in the `index()` action:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
fn (app &App) index() vweb.Result {
|
pub fn (app &App) index() vweb.Result {
|
||||||
articles := app.find_all_articles()
|
articles := app.find_all_articles()
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
blog.db
|
|
@ -1,4 +1,4 @@
|
||||||
drop table Article;
|
drop table if exists Article;
|
||||||
|
|
||||||
create table Article (
|
create table Article (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
|
|
|
@ -16,18 +16,18 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn (mut app App) index_text() vweb.Result {
|
pub fn (mut app App) index_text() vweb.Result {
|
||||||
app.vweb.text('Hello, world from vweb!')
|
app.vweb.text('Hello, world from vweb!')
|
||||||
return vweb.Result{}
|
return vweb.Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (app &App) index_html() vweb.Result {
|
pub fn (app &App) index_html() vweb.Result {
|
||||||
message := 'Hello, world from Vweb!'
|
message := 'Hello, world from Vweb!'
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn (app &App) index() vweb.Result {
|
pub fn (app &App) index() vweb.Result {
|
||||||
articles := app.find_all_articles()
|
articles := app.find_all_articles()
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue