Displaying an image from the database

Can someone help me display an image from a database?

I am trying to create an image tag for an image located in a
database. The following action is located in the
show_photo_controller.

def database_data
@photo = Photo.find(params[:id])
send_data(@photo.data,
:filename => @photo.name,
:type => @photo.content_type,
:disposition => “inline”)
end

If I go to the url http://localhost:3000/show_photo/database_data/1,
the photo displays properly. However, when I insert the following in
my view, it displays the image’s binary as text. Suggestions?

<%= image_tag(“/show_photo/database_data/1”, :alt => “Image”) %>

I’ve also pasted my code at Parked at Loopia. Thanks!

What happens if you put a .jpg after the 1 out of curiosity?

On Dec 11, 2007 10:51 AM, [email protected] [email protected] wrote:

           :filename => @photo.name,

I’ve also pasted my code at Parked at Loopia. Thanks!


Ryan B.

[email protected] wrote:

Can someone help me display an image from a database?

I am trying to create an image tag for an image located in a
database. The following action is located in the
show_photo_controller.

def database_data
@photo = Photo.find(params[:id])
send_data(@photo.data,
:filename => @photo.name,
:type => @photo.content_type,
:disposition => “inline”)
end

If I go to the url http://localhost:3000/show_photo/database_data/1,
the photo displays properly. However, when I insert the following in
my view, it displays the image’s binary as text. Suggestions?

<%= image_tag(“/show_photo/database_data/1”, :alt => “Image”) %>

I’ve also pasted my code at Parked at Loopia. Thanks!

change it to:
<%= image_tag(“/show_photo/database_data?id=1”, :alt => “Image”) %>
I don’t know why the standard routing doesn’t work in this case, but I
had same issue.

Great! <%= image_tag(“/show_photo/database_data?id=1”, :alt =>
“Image”) %> worked! Thanks!

On Dec 10, 6:44 pm, Joel N. [email protected]