# Routes - Preventing a Match

**URL:** <https://www.ruby-forum.com/t/routes-preventing-a-match/169612>\
**Category:** Rails\
**Created:** [June 5, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612 "2009-06-05T22:07:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 5, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/1 "2009-06-05T22:07:43Z")

</div>

The result that I’m trying to achieve is that URLs that begin with ‘/  
static’ do not get mapped.

My thought is that it sure would be nice if I could somehow say that  
if a URL begins with ‘/static’ simply abandon any further routing  
tests.

How can I best handle this?

Thanks for any input.

```
    ... doug
```

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 4:51am UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/2 "2009-06-06T04:51:00Z")

</div>

On Fri, Jun 5, 2009 at 10:06 PM, doug[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for any input.
> 
> ```
> ... doug
> 
> ```

Most rails websites are fronted by a different webserver that acts as a  
proxy.  
Set that proxy to handle static content and not even pass it to rails.

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)

[http://MyMvelope.com](http://MyMvelope.com) - The SIMPLE way to manage your savings

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 5:10am UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/3 "2009-06-06T05:10:52Z")

</div>

> Most rails websites are fronted by a different webserver that acts as a proxy.  
> Set that proxy to handle static content and not even pass it to rails.

OK. That’s a good suggestion where there is a front-end proxy. In  
this case, there isn’t. In any event, I would expect this to be a  
very simple problem to solve and I only blamed my own ignorance for  
the fact that I was having any difficulty at all. Am I to understand  
that this is a problem which does not have a simple solution?

Thanks for the input.

```
    ... doug
```

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 5:20am UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/4 "2009-06-06T05:20:48Z")

</div>

On Sat, Jun 6, 2009 at 5:09 AM, djolley[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the input.
> 
> ```
> ... doug
> 
> ```

If you are wanting Rails to stop processing, what should it do?  
What are you really wanting to achieve?

The normal use case is that static files are not served by Rails but  
in that circumstance, another server would serve them _before_ Rails.  
If you wanted to serve them _after_ Rails, then Rails shouldn’t stop  
processing but pass the request on somehow.

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)

[http://MyMvelope.com](http://MyMvelope.com) - The SIMPLE way to manage your savings

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 8:03am UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/5 "2009-06-06T08:03:15Z")

</div>

> If you are wanting Rails to stop processing, what should it do?  
> What are you really wanting to achieve?

I just want the URL to be served-up as a static page.

> The normal use case is that static files are not served by Rails but  
> in that circumstance, another server would serve them _before_ Rails.

I don’t understand that. As configured out-of-the-box Rails serves  
the static page public/index.html as a home page. Although I have  
never done it, I assume that I could simply modify that static page  
and use it as the home page for a site. I just want to accomplish  
essentially the same thing. I want to be able to have a few  
static .html pages in public/static, e.g. public/static/test1.html.  
In the case of this example, I don’t want ‘static’ to map to a  
controller and ‘test1’ map to an action. It would be my understanding  
that that is what would happen if there were some sort of beginning  
instruction in the routes.rb file to the effect that if a URL begins  
with /static there should be no further processing thus the standard  
mappings to a controller and an action would just not be invoked WRT  
that particular URL.

Anyway, I didn’t mean to get carried away here. I believed that I was  
just missing some minor point and that someone would square me away  
with ease. Apparently the point isn’t as trivial as I had thought.

Thanks for the input.

```
      ... doug
```

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 2:32pm UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/6 "2009-06-06T14:32:36Z")

</div>

2009/6/6 djolley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> the static page public/index.html as a home page. Â Although I have  
> that particular URL.  
> I think the point is that requests for the static pages never get as  
> far as routes.rb. They are handled before the processing gets to this  
> file so there is nothing that can be done in routes.rb to affect how  
> they are handled.

Colin

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 4:19pm UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/7 "2009-06-06T16:19:39Z")

</div>

I believe you could use rails new feature which is rails metal, it makes  
rails served the requested content without even touching the routing  
mechanism. I never use it though, maybe you can find the documentation  
on  
the rails site. 🙂

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/8 "2009-06-06T14:10:18Z")

</div>

You don’t need to change anything in your routes file for that to  
work.

Any static files that exist in the public folder (eg all your images/  
js/css or public/static/test1.html) will be served as static files.  
Don’t forget that the url to browse to these files is /static/  
test1.html and not /public/static/test1.html since it is the public  
folder and not the rails root that is the webserver root directory.

Cheers,  
Jeremy

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [June 6, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/routes-preventing-a-match/169612/9 "2009-06-06T17:53:12Z")

</div>

> Any static files that exist in the public folder (eg all your images/  
> js/css or public/static/test1.html) will be served as static files.

Well I’ll be darned! 🙂 It works great. How do these files escape  
being mapped by routes.rb? I notice that if I stick a file named  
index.html in /static and then try to proceed to the /static URL in a  
browser, Rails gives me a routing error. However, as you say, the  
file /static/test.html serves up just fine. Now, if I could just  
understand specifically why that is I think that I’d be finished with  
this topic.

> Don’t forget that the url to browse to these files is /static/  
> test1.html and not /public/static/test1.html since it is the public  
> folder and not the rails root that is the webserver root directory.

Yep, I totally have that. Thaks for pointing it out though as I do  
often make stupid mistakes.

Thanks very much for the input.

```
     .... doug
```
