WDI-SEA / project-2-issues

0 stars 0 forks source link

Cant get favorites to show up #40

Closed DagemBefikadu closed 2 years ago

DagemBefikadu commented 2 years ago
app.get('/profile', isLoggedIn, (req,res) => {
    console.log('This should be the userId', res.locals.currentUser.id)
    db.userCoffee.findAll({
        where:{ userId: res.locals.currentUser.id},
        include: [db.coffee, db.user]
    })
    .then((coffee) => {
        console.log('This should be the favorited Coffee',coffee)
        res.render('profile', {coffee: coffee})
    })
    .catch (error => {
        console.log(error)
    })
})
<% coffee.forEach(function(coffeeFavorite) {%>
    <div>
        <h3>
            <%= coffeeFavorite.name %>    
        </h3>
    </div>
<% }) %> 

The error that i got:

    1| <h2><%= currentUser.name %>'s Profile</h2>
    2| 
 >> 3| <% coffee.forEach(function(coffeeFavorite) {%>
    4|     <div>
    5|         <h3>
    6|             <%= coffeeFavorite.name %>    

coffee is not defined
timmshinbone commented 2 years ago

Where should coffee be coming from? what prints when you console log the data object that you're sending to your view template?

DagemBefikadu commented 2 years ago

The data base i think, nothing it catches that error i posted above first

TaylorDarneille commented 2 years ago

In your first screenshot I see you're passing through coffee in the render, which looks correct. But does the console.log above it show the list of coffee correctly?

DoireannJane commented 2 years ago

Hi Dagem, do you mind following the new template with your new issue?