我在检索存储在遗留oracle数据库中的blob图像时遇到了问题。当我进入http://server/images/id/type时,我会收到一个no implicit conversion of Symbol into Integer错误。
我有以下设置:
GemFile
gem 'rails', '3.2.13'
gem 'activerecord-oracle_enhanced-adapter'
gem 'ruby-oci8'表
CREATE TABLE "SCHEMA"."IMAGE_TABLE"
( "IMG_TYPE_SEQ_NO" NUMBER(12,0),
"IMG_TYPE" VARCHAR2(10 BYTE),
"IMG_DESC" VARCHAR2(60 BYTE),
"IMG_LENGTH" NUMBER,
"IMG_BLOB" BLOB
);模型
class Image < ActiveRecord::Base
self.table_name = 'schema.image_table'
def self.image_by_id_and_type(id, type)
where(
'img_type_seq_no = :id and img_type = :type',
id: id, type: type
)
end控制器
class ImagesController < ApplicationController
def show_image
@image = Image.image_by_id_and_type(params[:id], params[:type])
send_data @image[:img_blob], type: 'image/gif', disposition: 'inline'
end
end我尝试过使用send_data @image.img_blob,并得到了一个undefined method错误。
我做错了什么?
谢谢,克里斯
更新:
我想知道是否存在类型转换的问题。blob映像通过java swing应用程序持久化,该应用程序将其转换为java字节数组。这会是问题吗?如果是这样,我如何将java字节数组转换为send_data可以理解的内容?
发布于 2013-07-18 17:58:27
@image = Image.image_by_id_and_type(params[:id], params[:type])返回一个ActiveRecord::Relation对象,因此为了从它获得实际值,我必须调用first。
send_data @image.first[:img_blob], type: 'image/gif', disposition: 'inline'发布于 2013-07-16 16:49:46
这是个疯狂的猜测。请试一试
def show_image
@image = GiftCardImage.image_by_id_and_type(params[:id].to_i, params[:type])
send_data @image[:img_blob], type: 'image/gif', disposition: 'inline'
end在你的模型里
class Image < ActiveRecord::Base
self.table_name = 'schema.image_table'
def self.image_by_id_and_type(id, type)
where("img_type_seq_no = ? and img_type = ?", id, type)
endhttps://stackoverflow.com/questions/17682292
复制相似问题