chonsean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-11 00:21 UTC
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 http://pastie.caboo.se/126726. Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
What happens if you put a .jpg after the 1 out of curiosity? On Dec 11, 2007 10:51 AM, chonsean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <chonsean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 http://pastie.caboo.se/126726. Thanks! > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
chonsean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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 http://pastie.caboo.se/126726. 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
chonsean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-11 07:06 UTC
Re: Displaying an image from the database.
Great! <%= image_tag("/show_photo/database_data?id=1", :alt =>
"Image") %> worked! Thanks!
On Dec 10, 6:44 pm, Joel Nylund
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> chons...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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 urlhttp://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 athttp://pastie.caboo.se/126726.
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.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---