WDI-SEA / project-2-issues

0 stars 0 forks source link

Unable to view apartment listings when I click on them #41

Closed isaac8069 closed 2 years ago

isaac8069 commented 2 years ago

I get this message: Cannot GET /apartments/1 I'm wondering if its a url route issue. Also my UPDATE crashes my app. For now I have it commented out. Is it too late to start over??? I haven't been able to solve any issues on my own. I don't think its clicking and the more things i read/research is making me feel more lost

timmshinbone commented 2 years ago

sounds like a url route issue, you'll need to declare that route with /:id and set up a view template(something like show.ejs that will take that apartment and render it to the page.

DEFINITELY too late to start over, but you don't need to! Trying to set up a new app wont make the content click any more than it is now.

Share here what that route I mentioned above might look like, and also share some ejs that you would use to render that content on the screen, we'll hammer out the bugs from there

isaac8069 commented 2 years ago
router.get('/:id', (req, res) => {
  db.apartment.findOne({
    // include: [db.tag],
    where: { id: req.params.id }
  }).then((apartment) => {
    res.render('apartments/show', { apartment: apartment })
  }).catch((error) => {
    console.log(error)
    res.send('display apartments')
  })
})
isaac8069 commented 2 years ago

SHOW.EJS

<h1>Apartment: <%= apartment.title %></h1>

<p><%= apartment.title %></p>****
isaac8069 commented 2 years ago

Error: Cannot GET /apartments/7

I am still receiving the above error.

TaylorDarneille commented 2 years ago

that error means you don't have a get route in your controller that has a url pattern of /:id

isaac8069 commented 2 years ago

I have a get route with an id. Maybe i am missing what you are saying

router.get('/:id', (req, res) => {
  db.apartment.findOne({
    // include: [db.tag],
    where: { id: req.params.id }
  }).then((apartment) => {
    res.render('apartments/:id', { apartment: apartment })
  }).catch((error) => {
    console.log(error)
    res.send('display apartments')
  })
})
isaac8069 commented 2 years ago

Solution: <a href="/apartment/<%= apartment.id %>">

The solution was to remove the s in index.ejs from apartments in <a href="/apartments/<%= apartment.id %>">