私はmongooseとexpressjsを使用して記事を見つけて記事を作成しようとしています。検索フォームがあり、入力は変数「titles」に設定されています。
これが私のapp.jsファイルです:
app.get('/', function(req, res){
postdb.findAll( function(error,docs){
res.render('index.jade', {
locals: {
title: 'test',
articles:docs
}
});
})
});
app.post('/.:titles?', function(req, res) {
postdb.findByTitle(req.params.titless, function(error, article) {
res.render('blog_show.jade',
{ locals: {
title: article.title,
article:article
}
});
});
});
そしてここにfindbytitleメソッドがあります:
PostDB.prototype.findByTitle = function(titless, callback) {
this.getCollection(function(error, article_collection) {
if( error ) callback(error)
else {
article_collection.findOne({title: titless}, function(error,
result) {
if( error ) callback(error)
else callback(null, result)
});
}
});
};
検索ボタンをクリックすると、localhost /に転送されますか?titless =キーワードページですが、検索された記事がないインデックスページが表示されます:/。