Pass param in routes?

27 views
Skip to first unread message

Arjon Buikstra

unread,
Dec 4, 2013, 5:01:31 AM12/4/13
to locomo...@googlegroups.com
I apologize if this is a stupid question, but I've been trying to figure it out and couldn't find it in the docs or on this group.

Is there any way I can match things and route them straight to a resource, not just an action? E.g. I want to match /apple to pages#show with param(apple)
I want to do this:

    this.match('/apple', { controller: 'pages', action: 'show', apple : 'test'});

Is that possible, somehow?

Jean Friesewinkel

unread,
Dec 4, 2013, 9:18:11 AM12/4/13
to locomo...@googlegroups.com
Hi Arjon, 
Yes it is possible :)

in /config/routes.js

  this.match('/:name', 'pages#show');

in /app/controllers/pages_controller.js

PagesController.show = function() {
  console.log(this.param('name'));
  // going to localhost:3000/apple will now log 'apple'
  // ... render the page based on the param value
};


Cheers,

Jean

Arjon Buikstra

unread,
Dec 5, 2013, 5:11:21 AM12/5/13
to locomo...@googlegroups.com
Dear Jean,

Thank you for the response. 

I see that this route works, it also makes intuitive sense to me. But I want to be able to send people directly to /apple even if they have not typed that in their address bar..
So, I want not /:page to go there but, /something, or even /..

How can I manually declare a parameter in the route even though the user gave no such parameter?

Kind regards,

Arjon
Reply all
Reply to author
Forward
0 new messages