ga-wdi-exercises / project4

[project]
https://github.com/ga-wdi-exercises/project4
2 stars 8 forks source link

Can`t aceess show page json #527

Closed tedlayea closed 7 years ago

tedlayea commented 7 years ago

I can get index page JSON data but not show page. Here is part of my code:

// My catagoryController
show(req,res){
    Person.findOne({name: req.params.name},(err,contact)=>{
      console.log(contact);
      res.send(contact)
    })
  }
//index.js
app.get('/backend/:catagory', catagoryController.show)

screenshot

superbuggy commented 7 years ago

Does your program ever console.log the value of contact

tedlayea commented 7 years ago

Yes when I run my controller, it does. I can see the result in the terminal(not the browser).

superbuggy commented 7 years ago

since you have {name: req.params.name} as your 1st argument to .findOne(): Change

app.get('/backend/:catagory', catagoryController.show)`

to

app.get('/backend/:name', catagoryController.show)
tedlayea commented 7 years ago

I did it, but still no change.

superbuggy commented 7 years ago

What's the value of contact when it is logged?

tedlayea commented 7 years ago

If I run the controller and put this code: catagoriesController.show({catagoryName: "aaa"}) Then the log show me detail about aaa

superbuggy commented 7 years ago

You have data in your mongo db, right?

tedlayea commented 7 years ago

The previous image is screenshot when I use postman. Here is screenshot of browser screenshot2

tedlayea commented 7 years ago

Yes I have data I can see index page clearly.

superbuggy commented 7 years ago

Ah that's what I thought, badcfg refers to when an object is received instead of an array (single thing instead of a list of things). Instead of .query(), use .get().

tedlayea commented 7 years ago

ops now even I can`t see index page

superbuggy commented 7 years ago

I don't have a sense of where you are with your issue, can you include relevant code and errors?

tedlayea commented 7 years ago

now solved, thanks.

superbuggy commented 7 years ago

yay!