Skip to content

Commit

Permalink
Changed from a POST to a GET for the search page. Makes the result pa…
Browse files Browse the repository at this point in the history
…ge refreshable, also fits in with where I want to go with the API
  • Loading branch information
csainty committed Apr 6, 2012
1 parent e369d9b commit bfda944
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app.js
Expand Up @@ -56,7 +56,7 @@ app.get('/ask', require('./routes/ask.js'));
app.get('/create', require('./routes/create.js')); app.get('/create', require('./routes/create.js'));
app.get('/wat/:id', require('./routes/wat.js')); app.get('/wat/:id', require('./routes/wat.js'));


app.post('/search', require('./routes/search.js')); app.get('/search', require('./routes/search.js'));


app.listen(port, address); app.listen(port, address);


Expand Down
8 changes: 4 additions & 4 deletions routes/search.js
Expand Up @@ -4,14 +4,14 @@ var mongoose = require('mongoose')
; ;


module.exports = function (req, res) { module.exports = function (req, res) {
if (!req.body.q || req.body.q.length === 0) { return res.redirect('/'); } if (!req.query.q || req.query.q.length === 0) { return res.redirect('/'); }


Wat Wat
.find({ phrase: req.body.q }) .find({ phrase: req.query.q })
.populate('_user') .populate('_user')
.run(function (err, results) { .run(function (err, results) {
if (err) { return res.redirect('/error'); } if (err) { return res.redirect('/error'); }
if (results.length === 0) { return res.redirect(url.format({ pathname: '/create', query: { phrase: req.body.q } })); } if (results.length === 0) { return res.redirect(url.format({ pathname: '/create', query: { phrase: req.query.q } })); }
res.render('search', { title: 'say wat?', results: results, query: req.body.q }); res.render('search', { title: 'say wat?', results: results, query: req.query.q });
}); });
}; };
2 changes: 1 addition & 1 deletion views/index.jade
Expand Up @@ -5,7 +5,7 @@ div.row-fluid


div.row-fluid div.row-fluid
div.search div.search
form(method='POST', action='/search') form(method='GET', action='/search')
div.span8 div.span8
input(type='text', name='q') input(type='text', name='q')
div.span3 div.span3
Expand Down

0 comments on commit bfda944

Please sign in to comment.