This is the mongoose and express code:
app.get('/:user/:id', function (req, res){
usermodel.findOne({ user: req.params.user }, function (err, user){
var imagen = user.imagen.id(req.params.id);
console.log(imagen);
res.render('photo.ejs', {
user: user,
photo: imagen
});
});
});
And this is the output in the EJS template:
<img src="/users/<%= user._id %>/<%= user.avatar %>" class="img-circle" alt="">
I've a console.log, returning the imagen object. Just once. But I receive this:
{ title: 'Slimes',
name: 'slimes.png',
author: 'Mrmangado',
description: 'A collection of Slimes',
index: 1,
views: 7,
fav: 0,
path: '/users/5112b8da8a63aae76f000005/',
_id: 5112b91a8a63aae76f000006,
comments: [],
date: Wed Feb 06 2013 23:12:10 GMT+0300 (MSK),
tags: [ '#Slimes', '#DQ', '#Sprites' ] }
null
TypeError: /root/views/photo.ejs:92
>> 1| <img src="/users/<%= user._id %>/<%= photo.name %>" alt=""/>
I get the imagen object twice, the first is defined, but the second time has a value of null, so I get an error. Why? It's really weird why I get two request, maybe, to that URL. Any solution for this...?
Thank's advance!
I think both requests
/user/id and /usr/id/photoname execute the same code. Also the line erroring in your error dump is not the one you copied earlier.