Closed ChayoPerez closed 3 years ago
Hola 😁 .
Podrías enviar el error que te está levantando?
'TypeError: organizations.routes is not a function
at Object.
Este es el error!
Y podrías enviar el contenido de routes/organizations?
Perdón, no logro que github lea mi comentario como código D:
`const KoaRouter = require('koa-router'); const router = new KoaRouter();
const PERMITTED_FIELDS = [ "name", "url", ];
router.param("id", async (id, ctx, next) => { const organization = await ctx.orm.organization.findByPk(id); if (!organization) ctx.throw(404); // si no existe retorna not found ctx.state.organization = organization; return next(); });
router.get("organizations", "/organizations", async (ctx) => {
const organizations = await ctx.orm.organization.findAll({ include: "organization" });
/* organizations.forEach(org => {
org.dataValues.cloudinaryImage = cloudinary.url(org.image);
}); */
await ctx.render("organizations/index", {
organizations,
});
});
router.get("organizations-new", "/organizations/new", async (ctx) => { const organization = ctx.orm.organization.build(); return ctx.render("organizations/new", { organization, }); });
router.post("organizations-create", "/", async (ctx) => { const organization = ctx.orm.organization.build(ctx.request.body); try { await organization.save({ fields: PERMITTED_FIELDS }); ctx.redirect(ctx.router.url("organization", { id: organization.id })); } catch (error) { await ctx.render("organizations/new", { errors: error.errors, }); } });
router.get("organization-show", "organization/:id", async (ctx) => { const organization = await ctx.orm.organization.findByPk(id); return ctx.render("organizations/show", { organization, }); });`
No estás exportando router
.
Para insertar un bloque de código en md se usan tres backticks.
Ohhh muchas gracias! Ya me corre el programa :)
Hola! Estoy practicando para el examen e hice una aplicación de prueba, pero tuve un problema. Hice un model llamado organization y creé su route, pero cuando el programa lee routes.js no parece encontrarlo y tira el error del título :( El resto de las páginas (como el hello) sí funcionan.
`const KoaRouter = require('koa-router'); const router = new KoaRouter();
const hello = require('./routes/hello'); const index = require('./routes/index'); const organizations = require('./routes/organizations');
router.use('/', index.routes()); router.use('/hello', hello.routes()); router.use('/organizations', organizations.routes());
module.exports = router; ` Se cae en la penúltima línea.