Forum: Ruby on Rails Image from database and display

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.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2009-04-30 17:55
I have an image saved in a database and am trying to display it in my
view. Here is my code:

View-
<%= image_tag( url_for :action => 'image', :id => 1, :pseudo_id =>
@pseudo.id) %>

Controller-
@image = Image.find(:first, :conditions => ['enpseudo_id = ?',
@pseudo.id])
send_data @img.img, :content_type => 'image/gif'

What I get is a broken image, but the dimensions look like the correct
dimensions which makes me thing that it is actually reading the image
from the database but not displaying it correctly. Thanks in advance,

-S
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2009-04-30 20:22
I got it, here is what I did:

View:

  <%= image_tag("/admin/code_image/#{@image.id}", :alt => "Image") %>

Controller - code_image

  def code_image
    @image_data = Image.find_by_id(params[:id])
    @image = @image_data.img
    send_data (@image, :disposition => 'inline')
  end

Hope this is of some help to somebody.

-S
054ea2f04b5592b91f8223796cc53979?d=identicon&s=25 Brendon Whateley (brendon)
on 2009-04-30 20:31
(Received via mailing list)
Yes... the image is fetched by the browser as a completely separate
request, so you need to be able to handle that request.

On Apr 30, 11:22 am, Shandy Nantz <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.