views:

26

answers:

2

Hi All,

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 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

A: 

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'
marcgg
Thanks marcgg. Jeriko answer above is what I was looking for.
Imran
+1  A: 

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.

Jeriko
Perfect. This is exactly what I was looking for.Thanks Jeriko.
Imran
Great. Don't forget to accept the answer!
Jeriko