论坛首页 入门讨论版 Ruby

如何显示sqlserver中image字段类型的图片

浏览 175 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-05-15
我现在在ruby中已经把图片保存到数据库中,但是读不出来,
我是这样写的
def picture
@rypicture = RyPicture.find(params[:id])
send_data(@rypicture.data,
:filename => @rypicture.name,
:type => @rypicture.content_type,
:disposition => 'inline')
end

在show界面上该如何写呢?
   
时间:2008-05-16
已经解决。
保存地址,读数据时引用地址。
这样不保存在数据库里比较好,避免了影响数据库性能。
在activerecord里写
def picture=(picture_field)
self.name = base_part_of(picture_field.original_filename)
self.content_type = picture_field.content_type.chomp
#self.data = picture_field.read
self.image_url = "/images/" + self.name

File.open("#{RAILS_ROOT}/public/images/#{picture_field.original_filename}", "wb+") do |f|
f.write(picture_field.read)
end
end

def base_part_of(file_name)
File.basename(file_name).gsub(/[^\w._-]/, '')
end
其他地方正常处理就可以了
   
0 请登录后投票
论坛首页 入门讨论版 Ruby

跳转论坛:
JavaEye推荐