使用PUT / update方法后,为什么我的EJS视图无法渲染?

时间:2018-01-09 16:18:56

标签: javascript node.js express ejs

我正在使用NODE.js和Express构建CRUD配方应用程序。我现在可以创建一个新配方并删除配方,但是在更新配方时我遇到了问题。

继承我的控制器,路线,模型和视图的代码:

//controller.js
recipesController.update = (req, res) => {
  Recipes.update({
    recipe : req.body.recipe,
    category: req.body.category,
    area: req.body.area,
    instructions: req.body.instructions,
    ingredients: req.body.ingredients,
    measurement: req.body.measurement,
    img: req.body.img,
    tag: req.body.tag
  }, req.params.id)
  .then(() => {
    res.redirect(`/recipes`)
  })
  .catch(err => {
    res.status(400).json(err)
  });
};

这些是我的路线     //routes.js

recipesRouter.get('/', recipesController.index);
recipesRouter.get('/new', recipesController.new);
recipesRouter.get('/:id', recipesController.show);
recipesRouter.get('/:id/edit', recipesController.edit);
recipesRouter.put('/:id', recipesController.update);
recipesRouter.post('/', recipesController.create);
recipesRouter.delete('/:id', recipesController.delete);

这是我的模特     //models.js

Recipes.update = (recipes, id) => {
  return db.oneOrNone(`
    UPDATE recipes SET
    recipe = $1,
    category = $2,
    area = $3,
    instructions = $4,
    ingredients = $5,
    measurement = $6,
    img = $7,
    tag = $8,
    WHERE id = $9
    `,[recipes.recipe, recipes.category, recipes.area, recipes.instructions, recipes.ingredients, recipes.measurement, recipes.img, recipes.tag, id])
};

我的观点反映了我的模型(太长了,无法包含)。 想法?

0 个答案:

没有答案