0
我正在使用mongo
運行標準geddy
設置。我的模型沒有創建對象並且沒有提示
路線:
router.get('/submit').to('Urls.add');
router.post('/create').to('Urls.create');
控制器:
// invokes the form for submitting a new url
// sends form output to the create function
this.add = function (req, resp, params) {
this.respond({params: params});
};
// creates a new url object and saves it to the 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'});
}
});
};
型號:
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);
查看:
<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>
當我訪問/submit
並填寫表單時,我只是重新定向到同一表單。數據庫中沒有插入任何內容。這是我第一次使用geddy,所以我可能錯過了一些東西。
就是這樣,我缺少名稱參數。謝謝! – n0pe