Rymo4
Rymo4

Reputation: 471

Rails 3.1 Routing

I'm trying to route a particular object's show method to the root path of my app, but I'm having trouble routing it anywhere at all for that matter. So I guess this break down into two questions:

  1. If I wanted /pages/2 for example to go to the root path, how would I do this?

  2. Also, if I wanted to make the url take a name or some attribute (eg. /username would find_by_username and show the correct page) how would I do this?

I've looked at a couple railscasts and the rails guide on routing, but I seem to be missing something...

Any help would be much appreciated.

Upvotes: 0

Views: 265

Answers (1)

bor1s
bor1s

Reputation: 4113

First of all, I should warn you. Because you want to break down REST pattern. REST was well designed by clever folks and if you want to redefine some of it's functionality - so you have some incorrect logic in your App design.

Now to answer your question:
1. You can try something like this:

match "pages/:id", redirect {|params| "your_root_url" if params[:id] == 2}

2. Look at to_param documentation for more detail.

I hope i helped you alittle

Upvotes: 2

Related Questions