Forum: Ruby on Rails Make dynamical URL for binary data in rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2932e97aee5aad3e4a0aa21ed26b30b3?d=identicon&s=25 Yingqi Tang (anakintang)
on 2007-05-17 20:05
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.
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-05-17 20:13
(Received via mailing list)
> 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
This topic is locked and can not be replied to.