# Map.connect with pattern match

**URL:** <https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929>\
**Category:** Rails\
**Created:** [May 14, 2009, 3:09am UTC](https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929 "2009-05-14T03:09:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [May 14, 2009, 3:09am UTC](https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929/1 "2009-05-14T03:09:11Z")

</div>

I have a site that includes a Flash navigator banner.  
Rather than have the designer go in and change the links ($$), I would  
like to redirect his links to mine.

His links are in the form “pagename.html”.

I need each of these links to instead be directed to actions within my  
home controller.

I have done the following:

map.connect “pagename.html”,  
:controller =\> ‘home’,  
:action =\> ‘pagename’

which works fine as long as I was not displaying a page from a  
controller at the time. i.e. I was displaying a page from “public”.  
However, as we know, if I was displaying a page from the “step1”  
controller, this mapping would not work since the url is now  
“/step1/pagename.html”

Of course, I could make entries for every controller to handle this but  
what I really want to do is something like

map.connect “^.\*pagename.html”

so Rails ignores everything up to the pagename.html part.

I tried using

map.connect “\*pagename.html”

but this doesn’t work.

Any ideas?

THANK YOU IN ADVANCE,  
Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [May 14, 2009, 3:42am UTC](https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929/2 "2009-05-14T03:42:10Z")

</div>

I don’t know how intensive your link-redirector is, but if you’re on a  
recent version of rails that uses rack, I’d look into using rails  
metal to pattern match on the request and do your thing.

By pass rails entirely and gain some speed as well.

Here’s one guide: [#150 Rails Metal - RailsCasts](http://railscasts.com/episodes/150-rails-metal)

Otherwise you need to install a catchall route, but that can get messy  
if you use default routes as well.

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [May 14, 2009, 7:12pm UTC](https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929/3 "2009-05-14T19:12:48Z")

</div>

Not to be critical, but you must have the world’s weakest contract  
with this designer… at the very least, they should be willing to  
change the links to absolute paths (“/pagename.html”) so that the  
banner’s not _completely_ broken.

And a Flash nav banner? What is this, 1999? 🙂

On a more technical note, I’ve also run into the problem with legacy  
links like this. Another option would be to use mod\_rewrite (or  
equivalent if you’re not on Apache) to rewrite the links into the  
correct format.

–Matt J.

On May 13, 8:09 pm, Dan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [May 15, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929/4 "2009-05-15T22:53:17Z")

</div>

Matt J. wrote:

> Not to be critical, but you must have the world’s weakest contract  
> with this designer… at the very least, they should be willing to  
> change the links to absolute paths (“/pagename.html”) so that the  
> banner’s not _completely_ broken.
> 
> And a Flash nav banner? What is this, 1999? 🙂
> 
> On a more technical note, I’ve also run into the problem with legacy  
> links like this. Another option would be to use mod\_rewrite (or  
> equivalent if you’re not on Apache) to rewrite the links into the  
> correct format.
> 
> –Matt J.
> 
> On May 13, 8:09ï¿½pm, Dan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

You’re saying as the pages are prefixed with a forward slash, rails  
won’t try to preprend the controller name? That should work.

Actually, flash nav banners are all the rage again. Hard to find a  
decent site without one–and for good reason. What else comes close in  
terms of eye-catching quality?

Thanks,  
Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [May 16, 2009, 5:12pm UTC](https://www.ruby-forum.com/t/map-connect-with-pattern-match/167929/5 "2009-05-16T17:12:09Z")

</div>

The browser is the one actually adding the controller name - it sees a  
bare, slash-less reference as relative to the current URL’s directory  
(the controller). The initial slash makes it an absolute path,  
avoiding that problem.

–Matt J.

On May 15, 3:53 pm, Dan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
