Adonis.js : E_ROUTE_NOT_FOUND: 找不到路由 POST /posts/add
Adonis.js : E_ROUTE_NOT_FOUND: Route not found POST /posts/add
我刚开始学习Adonis.js。我正在学习教程。
我正在尝试将数据保存到数据库中。这是我的代码
Add.edge
@layout('main')
@section('content')
<a href="/posts">Go back</a>
<hr>
<h1>Add Post</h1>
<form actions="/posts" method="POST">
{{csrffield}}
<div class="form-group">
<label>Title</label>
<input type="text" name="title" id="title" class="form-control" placeholder="title">
</div>
<div class="form-group">
<label>Body</label>
<input type="text" name="title" id="body" class="form-control" placeholder="body">
</div>
<button class="btn btn-primary" type="submit">
Submit
</button>
</form>
Route.js
Route.on('/').render('home')
Route.get('/posts', 'PostController.index')
Route.get('/posts/add', 'PostController.add')
Route.get('/posts/:id', 'PostController.details')
Route.post('/posts', 'PostController.store')
PostController
class PostController {
async add ({ view }) {
return view.render('posts.add')
}
async store({ request, response, session }) {
const post = new Post();
post.title = request.input('title')
post.body = request.input('body')
await post.save()
session.flash({ notification: 'Post Added!' })
return response.redirect('/posts')
}
提交表单时出现错误
E_ROUTE_NOT_FOUND: Route not found POST /posts/add
我的路线应该是这样的
Route.post('/posts/add', 'PostController.store').as('post.store')
我刚开始学习Adonis.js。我正在学习教程。
我正在尝试将数据保存到数据库中。这是我的代码
Add.edge
@layout('main')
@section('content')
<a href="/posts">Go back</a>
<hr>
<h1>Add Post</h1>
<form actions="/posts" method="POST">
{{csrffield}}
<div class="form-group">
<label>Title</label>
<input type="text" name="title" id="title" class="form-control" placeholder="title">
</div>
<div class="form-group">
<label>Body</label>
<input type="text" name="title" id="body" class="form-control" placeholder="body">
</div>
<button class="btn btn-primary" type="submit">
Submit
</button>
</form>
Route.js
Route.on('/').render('home')
Route.get('/posts', 'PostController.index')
Route.get('/posts/add', 'PostController.add')
Route.get('/posts/:id', 'PostController.details')
Route.post('/posts', 'PostController.store')
PostController
class PostController {
async add ({ view }) {
return view.render('posts.add')
}
async store({ request, response, session }) {
const post = new Post();
post.title = request.input('title')
post.body = request.input('body')
await post.save()
session.flash({ notification: 'Post Added!' })
return response.redirect('/posts')
}
提交表单时出现错误
E_ROUTE_NOT_FOUND: Route not found POST /posts/add
我的路线应该是这样的
Route.post('/posts/add', 'PostController.store').as('post.store')