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:
If I wanted /pages/2 for example to go to the root path, how would I do this?
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
精彩评论