views:

480

answers:

1

I'm trying to display images using my web application written in Rails. I've come across solutions like PaperClip, Attachment Fu etc; but they modify my data model and require to save the image through UI. The problem is that, the images content is not stored using Rails, but a Java Servlet Application. Is there a way to just display the blob content of image to my View.

-Snehal

+2  A: 
class ImagesController < ApplicationController
  caches_page :show
  def show
    if @image = Image.find_by_file_name(params[:file_name])
      send_data(
        @image.file_data, 
        :type => @image.content_type,
        :filename => @image.file_name,
        :disposition => 'inline'
      )
    else
      render :file => "#{RAILS_ROOT}/public/404.html", :status => 404
    end
  end
end

map.connect "/images/*file_name", :controller => "images", :action => "show"

Or something like that.

BJ Clark
Thanks Clark! This is exactly what I was looking for
Snehal