Reputation: 29777
I have the binary data for an image in my controller action. I need to display the image in the view. How can I do this? I'm using Ruby 1.9.2 and Rails 3.0.1.
Upvotes: 0
Views: 997
Reputation: 106027
As coreyward above notes, it's not ideal to be doing this at all. But if you don't have an alternative (really, you probably do), you should look into data URIs.
It depends on what format your binary data is in, but the short version is that you will convert the data to a Base64-encoded string and then build a special URI that starts with data:
, followed by the appropriate MIME type, and then the base64 string, and use that as the src
attribute in a normal <img />
tag.
Upvotes: 2