1
我试图用Rails编写我的web应用程序来显示图像。我遇到了PaperClip,Attachment Fu等解决方案;但他们修改我的数据模型并需要通过UI保存图像。问题是,图像内容不是使用Rails存储的,而是一个Java Servlet应用程序。有没有办法只显示图像的blob内容到我的视图。如何在不使用插件的情况下在Rails中显示图像?
-Snehal
我试图用Rails编写我的web应用程序来显示图像。我遇到了PaperClip,Attachment Fu等解决方案;但他们修改我的数据模型并需要通过UI保存图像。问题是,图像内容不是使用Rails存储的,而是一个Java Servlet应用程序。有没有办法只显示图像的blob内容到我的视图。如何在不使用插件的情况下在Rails中显示图像?
-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"
或类似的东西。
谢谢克拉克!这正是我所期待的 – Snehal 2009-11-02 07:57:08
我完全不知道这个问题。回形针或attachment_fu都不要求您使用UI将图像存储在服务器上。 – 2009-11-02 06:37:45