I have a problem with AdonisJS I am trying to create a form to send data by POST, but at the time of placing the token I get the following error "Can not call function csrfField from", now if I deactivate the shield and remove the function {{ csrfField ()}} the form runs without any problem but I do not want to leave the forms checked out. I already probe with the reinstallation of AdonisJS and reinstalling the shield including placing the providers in start / app.js and placing it in the Kernel. Any ideas?
So I have the form
<form action="{{ route('libros.guardar') }}" method="post">
{{ csrfField() }}
<div class="form-group">
<label for="code">Code</label>
<input type="text" class="form-control" name="code" id="code" aria-describedby="code" placeholder="Code del libro">
</div>
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" class="form-control" name="nombre" id="nombre" aria-describedby="nombre" placeholder="Nombre del libro">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Descriptción</label>
<textarea class="form-control" id="name" id="descripcion" placeholder="Descriptción del libro"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
The app.js
const providers = [
'@adonisjs/framework/providers/AppProvider',
'@adonisjs/framework/providers/ViewProvider',
'@adonisjs/lucid/providers/LucidProvider',
'@adonisjs/bodyparser/providers/BodyParserProvider',
'@adonisjs/cors/providers/CorsProvider',
'@adonisjs/shield/providers/ShieldProvider',
'@adonisjs/session/providers/SessionProvider',
'@adonisjs/auth/providers/AuthProvider'
]
And the kernel.js
const globalMiddleware = [
'Adonis/Middleware/BodyParser',
'Adonis/Middleware/Session',
'Adonis/Middleware/Shield',
'Adonis/Middleware/AuthInit'
]
I have seen that there is a problem with the call to the route, if I do it in the following way:
Route.on('/libros/agregar').render('libros.agregar')
It works, but if I make the call from the controller it does not work:
Route.get('/libros/agregar', 'LibroController.agregar').as('libros.agregar')
Controller:
'use strict'
const View = use('View')
class LibroController{
agregar(){
return View.render('libros.agregar')
}
}