How to display images in Rails without plugins like Paper Clip?
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
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.
精彩评论