node.js - My model isn't creating objects and failing silently -


i'm running standard geddy setup mongo.

routes:

router.get('/submit').to('urls.add'); router.post('/create').to('urls.create'); 

controller:

// invokes form submitting new url // sends form output create function this.add = function (req, resp, params) {     this.respond({params: params}); };  // creates new url object , saves database this.create = function (req, resp, params) {     var self = this;     var timestamp = new date().gettime();     var url = geddy.model.url.create({         title: params.title,          url: params.url,         score: 0,         created: timestamp     });     url.save(function(err, data) {         if (err) {             params.errors = err;             self.transfer('add');         } else {             this.redirect({controller: 'url.index'});         }     }); }; 

model:

var url = function () {     this.defineproperties({         title:   {type:'string', required:true},         url:     {type:'string', required:true},         score:   {type:'int', required:true},         created: {type:'datetime', required:true}     });      this.validatespresent('title');     this.validatespresent('url'); };  url = geddy.model.register('url', url); 

view:

<div class="row"> <form class="form-horizontal" role="form" action="/create" method="post">     <div class="form-group">         <label for="title" class="col-lg-1 control-label">title</label>         <div class="col-lg-7">             <input type="text" class="form-control" id="title" placeholder="title">         </div>     </div>     <div class="form-group">         <label for="url" class="col-lg-1 control-label">url</label>         <div class="col-lg-7">             <input type="text" class="form-control" id="url" placeholder="url">         </div>     </div>     <div class="form-group">         <div class="col-lg-offset-1 col-lg-7">             <button type="submit" class="btn btn-default">submit</button>         </div>     </div> </form> </div> 

when visit /submit , fill out form, redirected same form again. nothing gets inserted in database. first time using geddy i'm missing something.

it looks not printing out error in view, can't see why failed.

from looks of it, it's failing because required variables missing. you'll need name attributes on form fields, not id, or server never values.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -