Created
October 25, 2017 08:29
-
-
Save ammezie/19bb96678f4c6b820832fc504b4b00c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// start/routes.js | |
Route.get('tasks/:id/edit', 'TaskController.edit') // updated this slightly | |
Route.patch('tasks/:id', 'TaskController.update') | |
// For the PATCH method, you might want to take a look at - http://dev.adonisjs.com/docs/4.0/request#_method_spoofing | |
// TaskController.js | |
async update ({ request, params, response, session }) { | |
// Get the task you want to update | |
const task = await Task.find(params.id) | |
// validate form input | |
const validation = await validate(request.all(), { | |
title: 'required|min:3|max:255' | |
}) | |
// show error messages upon validation fail | |
if (validation.fails()) { | |
session.withErrors(validation.messages()) | |
.flashAll() | |
return response.redirect('back') | |
} | |
// persist changes to database | |
task.title = request.input('title') | |
await task.save() | |
// Fash success message to session | |
session.flash({ notification: 'Task update!' }) | |
return response.redirect('back') | |
} |
Hi @ammezie,
This is what my edit form looks like
<form action="{{ 'tasks/' + task.id + '?_method=PUT' }}" method="POST">
However I keep ending up with this URL route:
http://127.0.0.1:3333/tasks/3/tasks/3?_method=PUT
Which results in getting an error:
HttpException
Route not found /tasks/3/tasks/3
What can I do to address this?
Thanks
Since you are using PUT
, change your route to use it instead of PATCH
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome. Thanks for the update on this