Skip to content

Problem Adding Truck#5

Closed
dianezev wants to merge 2 commits intoJSCRIPT300-Spring2015:masterfrom
dianezev:master
Closed

Problem Adding Truck#5
dianezev wants to merge 2 commits intoJSCRIPT300-Spring2015:masterfrom
dianezev:master

Conversation

@dianezev
Copy link

Hi James,

'Add Food Truck' is not working for me and I can't figure out why. If I add new truck info in the UI & click 'Add Food Truck', I get 'undefined' at the bottom of the truck list. Clicking on that gives me an empty object such as {"_id":"5553b545f7d30fa41db53471","__v":0,"payment":[],"schedule":[],"foodType":[]}

When I use Mongo to check the data, the empty object is there as well.

Any suggestions are welcome! (I've only worked on part 1 so far)

Thank you,
Diane

@jamdon
Copy link
Contributor

jamdon commented May 14, 2015

You're missing one step. You've required the body-parser module, but you need to use the middle-ware function that calling bodyParser.urlencoded() returns. That middle-ware is responsible for extracting the post information and assigning it to the request.body object. It would look like this:
app.use(bodyParser.urlencoded({ extended: true }));

alternatively, to be more explicit:

// urlencoded returns a middle-ware function that you would then "use"
var parseUrlEncoded = body.parser.urlencoded({ extended: true });
app.use(parseUrlEncoded);

@dianezev
Copy link
Author

Thanks for the earlier help. I tried to use underscore in client.js in order to sort the truckList, but I couldn't get var _ = require('underscore'); to work. Any suggestions?

@jamdon
Copy link
Contributor

jamdon commented May 15, 2015

Using require() will only work using Node right now. There's a way to require code in client-side JavaScript, but it involves using another library to facilitate it such as Require.js or Browserify, which we won't have time to cover. Instead, what you want to do is add a script reference to the index.html that pulls in underscore. It will declare _ globally, so just make sure you include it before the client.js script reference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add a script reference to index.html that includes the underscore library:

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

Make sure it appears before the client.js script reference.

@jamdon
Copy link
Contributor

jamdon commented May 16, 2015

👍

@jamdon jamdon closed this May 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants