开发者

Rails route with N number of parameters

I have application which allow users to create there on URL for a page on a particular domain.

What I want to achieve is to create URL having variable number of parameters separated开发者_C百科 by "/". For example:

www.mydomain.com/a

ww.mydomain.com/a/b

www.mydomain.com/a/b/c

and so on. After the root, everything would be considered as parameters. The final result I need in Rails code is two strings:

1."www.mydomain.com" 2. "a" or "a/b" or "a/b/c" (whatever is after the root)

Thanks, Imran


Sounds like you want a catch-all route. Add the following line to your routes.rb file:

map.connect '*path', :controller => 'your_controller' :action => 'your_action'

No matter what URL is supplied, the request path is captured and delimited by / into an array. You can access this via params[:path].

Since this will match any and every request, any other routes you have should be declared before this one.

Check out Ryan Bates' catch-all route railscast for more info.


You should look into the Rails Guide "Rails Routing from the Outside In ".

I'm not sure if I get your question, but it seems that you want something close to:

map.connect ':first_id/:second_id/:third_id'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜