# Rails 3: Routing constrants issue

**URL:** <https://www.ruby-forum.com/t/rails-3-routing-constrants-issue/193992>\
**Category:** Rails\
**Created:** [August 27, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/rails-3-routing-constrants-issue/193992 "2010-08-27T16:22:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenngore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@glenngore](https://www.ruby-forum.com/u/glenngore)\
**Post date:** [August 27, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/rails-3-routing-constrants-issue/193992/1 "2010-08-27T16:22:56Z")

</div>

Hi,

I’d like to have a route that looks like:

[http://webhost.com/myresource/random.server.com/folderOnServer/resourceName](http://webhost.com/myresource/random.server.com/folderOnServer/resourceName)

The params I’d like to come out of that are:

:server = [random.server.com](http://random.server.com)  
:folder = folderOnServer  
:resource = resourceName

So, I do this:

get ‘myresource/\*server/(:folder)/\*mapservice’ =\> “controller#action”,  
:constraints ={:server=\>/[^/]+/}

Which I hope is saying, I want to match all characters for the server  
param, until you get to the first /.

What is happening is:

:server = [random.server.com/folderOnServer](http://random.server.com/folderOnServer)  
:folder = nil  
:resource = resourceName

Any suggestions on what I am doing wrong?

Thanks,  
Glenn

---

<div class="post-metadata">

**Author:** ![glenngore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@glenngore](https://www.ruby-forum.com/u/glenngore)\
**Post date:** [August 27, 2010, 10:46pm UTC](https://www.ruby-forum.com/t/rails-3-routing-constrants-issue/193992/2 "2010-08-27T22:46:52Z")

</div>

On 27 August 2010 15:22, Glenn G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So, I do this:  
> :folder = nil  
> :resource = resourceName
> 
> Any suggestions on what I am doing wrong?

The asterisk before ‘server’ turns on globbing (which makes it gobble  
up as much of the URL as possible), and the parentheses around  
‘:folder’ tell the router that it’s an optional part of the route. So  
the router shoves as much as it can into the ‘server’ parameter, and  
leaves out the ‘folder’ parameter.

Also, I don’t really understand the ‘\*mapservice’ bit of your route,  
but guessing that’s just a typo.

I would just try:

get ‘myresource/:server/:folder/:resource’ =\> ‘votes#cast’,  
:constraints =\> {:server =\> /[^/]+/}

(where the constraint on ‘server’ is just to allow '.'s).

Chris
