Make dynamical URL for binary data in rails


#1

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.


#2

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