# Route to static resource?

**URL:** <https://www.ruby-forum.com/t/route-to-static-resource/165734>\
**Category:** Rails\
**Created:** [April 16, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734 "2009-04-16T20:46:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/1 "2009-04-16T20:46:31Z")

</div>

Is there any way to write a route that delivers a static resource?

For some reason something (looks like Google Toolbar according to the  
user-agent string) is requesting favicon.ico at all sorts of weird  
places, not just at the root location where favicon.ico belongs, but at  
/someAction/favicon.ico, etc.

I’d like to direct these all to the actual favicon.ico, to keep them out  
of my error logs.

If I can’t do it in routes, I guess I can do it in apache.

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 8:58pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/2 "2009-04-16T20:58:31Z")

</div>

On Apr 16, 2009, at 2:46 PM, Jonathan R. wrote:

> of my error logs.
> 
> If I can’t do it in routes, I guess I can do it in apache.
> 
> ## Thanks for any help!

Do you have something in your layout that says to find “favicon.ico”  
that could just be changed to “/favicon.ico” perhaps?

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/3 "2009-04-16T21:08:17Z")

</div>

Rob B. wrote:

> Do you have something in your layout that says to find “favicon.ico”  
> that could just be changed to “/favicon.ico” perhaps?

Nope, it’s nothing in my layout anywhere. It’s Google Toolbar acting up  
for some reason. Apparently others have seen it too:  
[http://www.google.com/support/forum/p/Toolbar/thread?tid=78479dcc02044f76&hl=en](http://www.google.com/support/forum/p/Toolbar/thread?tid=78479dcc02044f76&hl=en)

But still wondering if I can ‘route’ to a static resource, occasionally  
need that for other purposes too.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/4 "2009-04-16T21:50:14Z")

</div>

The problem is a catch-all route at the end would be AFTER the default

map.connect ‘:controller/:action/:id’

type routes. So weird routes that things like Google Toolbar and  
MS Word keep sending like “fake/notAnAction.gif” would not get caught by  
my catch-all, right?

I guess apache is the way to go.

Or, in another question I posted in another thread, figure out how to  
keep Rails from putting a backtrace in for these kind of errors in  
general. Haven’t figured out where in Rails is actually generating that  
annoying backtrace in production.log in the first place.

Philip H. wrote:

> You could add a catch-all route at the end that checks for  
> “favicon.ico” and then send-file the real favicon.ico back. Or to  
> speed it up do it using rack/metal.
> 
> But if were me, I’d do it in apache. That will definitely be the  
> fastest.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/5 "2009-04-16T21:45:59Z")

</div>

> occasionally  
> need that for other purposes too.

You could add a catch-all route at the end that checks for  
“favicon.ico” and then send-file the real favicon.ico back. Or to  
speed it up do it using rack/metal.

But if were me, I’d do it in apache. That will definitely be the  
fastest.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 9:51pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/6 "2009-04-16T21:51:17Z")

</div>

Philip H. wrote:

> You could add a catch-all route at the end that checks for  
> “favicon.ico” and then send-file the real favicon.ico back. Or to  
> speed it up do it using rack/metal.
> 
> But if were me, I’d do it in apache. That will definitely be the  
> fastest.

Woops, I forgot my real question. Right, I can do a catch-all like that  
(I actually did figure out a way to do that) – but how do I have a  
rails route send back a static file?

Do I need to create a method in application.rb for sending back the  
static file? Any way to tell a route to result in a static file?

THAT was my original question!

Jonathan

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 16, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/route-to-static-resource/165734/7 "2009-04-16T21:56:37Z")

</div>

> rails route send back a static file?  
> You don’t. Look at the ‘send\_data’ method in action controller.

> Do I need to create a method in application.rb for sending back the  
> static file? Any way to tell a route to result in a static file?

If you’re going to do this in Rails and you’re using a version that  
supports Rack, do it in rails metal. It will be a _lot_ simpler and  
keep the entire thing out of your logs.

> **[\#150 Rails Metal - RailsCasts](http://railscasts.com/episodes/150-rails-metal)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

-philip
