3

Currently a user comes to my register page with an invitation ID

Example: http://www.mysite.com/user/register/50e203eb4d37bdfd22000042

The page loads and the form loads etc.... all is great. I then do some back end validation and if validation fails I call the res.render with the messages and the form data:

res.render('user/register', {
    messages: messages 
    , form: form 

});

It all works as expected however when the render occurs it puts the user back to:

http://www.mysite.com/user/register (its missing the invite_id)

How can I pass along a URL param with the res render?

If I do:

res.render('user/register/50e203eb4d37bdfd22000042', {
    messages: messages 
    , form: form 

});

Its actually looking for that 50e203.... file and giving me the 404 not found

Thanks!

nwkeeley
  • 1,397
  • 5
  • 18
  • 28
  • This post seems similar to what you are looking for: http://stackoverflow.com/questions/6784753/passing-route-control-with-optional-parameter-after-root-in-express – sheldonk Jan 02 '13 at 02:27

1 Answers1

4

Are you perhaps confusing res.render() with app.get()? It looks like you're trying to specify a route in that second example: res.render('user/register/50e203eb4d37bdfd22000042'... - but res.render doesn't specify routes, you need app[METHOD] for that, where app is an express instance.

In order to handle a GET request to /user/register/someinvite, use:

app.get('/user/register/:invitation', function(req, res, next) {
// in here you can access the invitation id with req.params.invitation
  res.render('user/register');
});
hunterloftis
  • 13,386
  • 5
  • 48
  • 50
  • Actually I was an idiot.... I just needed to concact the ID into the form action in the jade template... I was mixing up the res.render with the url! – nwkeeley Jan 03 '13 at 15:03