Last active
December 17, 2015 08:19
-
-
Save gabrielstuff/5579235 to your computer and use it in GitHub Desktop.
An error with my request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'), | |
Config = mongoose.model('Config') | |
exports.create = function(req, res) { | |
debugger; | |
var conf = new Config(req.body); | |
conf.save(function(err) { | |
if (err) throw new Error('Error while saving option'); | |
console.log("Ouray !"); | |
res.redirect('/config'); | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends ../layouts/default | |
block content | |
- var action = '/config' | |
if (typeof errors !== 'undefined') | |
.fade.in.alert.alert-block.alert-error | |
a.close(data-dismiss="alert", href="javascript:void(0)") x | |
ul | |
each error in errors | |
li= error.type | |
.row | |
.span7 | |
form.form-horizontal(method="post", action=action, enctype="multipart/form-data") | |
.control-group | |
label.control-label(for='config[title]') Title | |
.controls | |
input#title.input-xlarge(type='text', name="config[title]", value=config.title, placeholder='Enter the title of the site') | |
.control-group | |
label.control-label(for='config[facebook][clientID]') Facebook clientID | |
.controls | |
if(typeof(config.facebook) !== 'undefined') | |
- var clientID = config.facebook.clientID | |
else | |
- var clientID = "" | |
input#title.input-xlarge(type='text', name="config[facebook][clientID]", value=clientID, placeholder='clientID') | |
.control-group | |
label.control-label(for='config[facebook][clientSecret]') Facebook clientSecret | |
.controls | |
if(typeof(config.facebook) !== 'undefined') | |
- var clientSecret = config.facebook.clientSecret | |
else | |
- var clientSecret = "" | |
input#title.input-xlarge(type='text', name="config[facebook][clientSecret]", value=clientSecret, placeholder='clientSecret') | |
.control-group | |
label.control-label(for='config[facebook][callbackURL]') Facebook callbackURL | |
.controls | |
if(typeof(config.facebook) !== 'undefined') | |
- var callbackURL = config.facebook.callbackURL | |
else | |
- var callbackURL = "" | |
input#title.input-xlarge(type='text', name="config[facebook][callbackURL]", value=callbackURL, placeholder='callbackURL') | |
.control-group | |
label.control-label(for='config[ftp][path]') Absolute path to ftp Image uploads | |
.controls | |
if(typeof(config.ftp) !== 'undefined') | |
- var ftpPath = config.ftp.path | |
else | |
- var ftpPath = "" | |
input#title.input-xlarge(type='text', name="config[ftp][path]", value=ftpPath, placeholder='/path/to/ftp/uploads') | |
.control-group | |
label.control-label(for='config[ftp][www]') Absolute path to www (Apache directory) | |
.controls | |
if(typeof(config.ftp) !== 'undefined') | |
- var ftpWWW = config.ftp.www | |
else | |
- var ftpWWW = "" | |
input#title.input-xlarge(type='text', name="config[ftp][www]", value=ftpWWW, placeholder='/www/data') | |
.form-actions | |
button.btn.btn-primary(type='submit') Save changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The model : | |
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema | |
var ConfigSchema = new Schema({ | |
config: Schema.Types.Mixed | |
, createdAt: {type : Date, default : Date.now} | |
}) | |
mongoose.model('Config', ConfigSchema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//does not work | |
curl -i -X POST -d 'config[title]=sas&config[facebook][clientID]=soapjs&config[facebook][clientSecret]=&config[facebook][callbackURL]=&config[pixcube][path]=booooob&config[cube][www]=' http://localhost:3000/config | |
//throw | |
< TypeError: Cannot read property 'name' of undefined | |
< at model.Document.set (/Users/gabrielstuff/Sites/app_test/node_modules/mongoose/lib/document.js:435:49) | |
< at model.Document (/Users/gabrielstuff/Sites/app_test/node_modules/mongoose/lib/document.js:61:10) | |
< at model.Model (/Users/gabrielstuff/Sites/app_test/node_modules/mongoose/lib/model.js:38:12) | |
< at new model (/Users/gabrielstuff/Sites/app_test/node_modules/mongoose/lib/model.js:2125:11) | |
< at exports.create (/Users/gabrielstuff/Sites/app_test/app/controllers/configs.js:10:18) | |
< at callbacks (/Users/gabrielstuff/Sites/app_test/node_modules/express/lib/router/index.js:161:37) | |
< at param (/Users/gabrielstuff/Sites/app_test/node_modules/express/lib/router/index.js:135:11) | |
< at pass (/Users/gabrielstuff/Sites/app_test/node_modules/express/lib/router/index.js:142:5) | |
< at Router._dispatch (/Users/gabrielstuff/Sites/app_test/node_modules/express/lib/router/index.js:170:5) | |
< at Object.router (/Users/gabrielstuff/Sites/app_test/node_modules/express/lib/router/index.js:33:10)app_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config: | |
{ title: 'foo', | |
facebook: | |
{ clientID: 'bar', | |
clientSecret: '', | |
callbackURL: '' }, | |
ftp: { path: '', www: 'as' } } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But this works :