# Rails app supplying image to a static page?

**URL:** <https://www.ruby-forum.com/t/rails-app-supplying-image-to-a-static-page/156574>\
**Category:** Rails\
**Created:** [December 30, 2008, 8:18am UTC](https://www.ruby-forum.com/t/rails-app-supplying-image-to-a-static-page/156574 "2008-12-30T08:18:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mksys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/858c86/32.png) [@mksys](https://www.ruby-forum.com/u/mksys)\
**Post date:** [December 30, 2008, 8:18am UTC](https://www.ruby-forum.com/t/rails-app-supplying-image-to-a-static-page/156574/1 "2008-12-30T08:18:29Z")

</div>

Can anyone help point me in the right direction on doing the  
following?

Say I have a Rails app that deals with photos at [photo.website.com](http://photo.website.com),  
and I also have a legacy site at [www.website.com](http://www.website.com).

What I would like to do is from a static html page on [www.website.com](http://www.website.com)  
have a random photo displayed from the photo app.

So, if I put something like this in my static page: ![]()  
would it be possible when a user hits the static page to have it  
routed to an action that would pull a random photo and return it to  
the static page in the form of an image?

Thanks in advance.  
Mark

---

<div class="post-metadata">

**Author:** ![mksys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/858c86/32.png) [@mksys](https://www.ruby-forum.com/u/mksys)\
**Post date:** [December 30, 2008, 9:39am UTC](https://www.ruby-forum.com/t/rails-app-supplying-image-to-a-static-page/156574/2 "2008-12-30T09:39:13Z")

</div>

well, i don’t know much about your rails app. so i can’t tell you how  
exactly you should do it. but generally spoken: yes, that should be  
possible. actually in exactly the way you proposed.

---

<div class="post-metadata">

**Author:** ![mksys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/858c86/32.png) [@mksys](https://www.ruby-forum.com/u/mksys)\
**Post date:** [December 30, 2008, 9:52am UTC](https://www.ruby-forum.com/t/rails-app-supplying-image-to-a-static-page/156574/3 "2008-12-30T09:52:42Z")

</div>

Hi Mark,

I would be inclined to create a controller and have an action on it that  
serves up a random image.

This would make your static URL something like

[http://photo.website.com/random/pic](http://photo.website.com/random/pic)

Create a controller called random, and an action called pic (you can  
call  
these anything, or even use the default index action). In your action,  
just pick a random image and serve it back to the browser.

We do something similar, without the randomness to serve images to  
external applications.

Cheers  
Simon
