开发者

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 co开发者_JS百科rrect 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜