# Make dynamical URL for binary data in rails

**URL:** <https://www.ruby-forum.com/t/make-dynamical-url-for-binary-data-in-rails/104422>\
**Category:** Rails\
**Created:** [May 17, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/make-dynamical-url-for-binary-data-in-rails/104422 "2007-05-17T20:05:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [May 17, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/make-dynamical-url-for-binary-data-in-rails/104422/1 "2007-05-17T20:05:15Z")

</div>

All,

I would like to do following thing: when the request reaches certain  
method in a controller, I want to read binary data (e.g. an image) from  
database and dynamically make up a URL (without writing that out  
physically), so in the view template I could reference that URL.

How can I do that in rails?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [May 17, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/make-dynamical-url-for-binary-data-in-rails/104422/2 "2007-05-17T20:13:35Z")

</div>

> I would like to do following thing: when the request reaches certain  
> method in a controller, I want to read binary data (e.g. an image) from  
> database and dynamically make up a URL (without writing that out  
> physically), so in the view template I could reference that URL.
> 
> How can I do that in rails?

Have a controller/action with a url like: /images/show/123

And in the show() method find the image you want then use send\_data().  
For example:

send\_data image.data, :type =\> image.content\_type,  
:disposition =\> ‘inline’

-philip
