2013-07-16 84 views
0

我有一個問題檢索存儲爲一個blob在舊的oracle數據庫中的圖像。當我去http://server/images/id/type時,我收到一個no implicit conversion of Symbol into Integer錯誤。Rails的send_data與oracle增強適配器

我有以下設置:

的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可以理解的東西?

回答

0
@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' 
0

這是一個瘋狂的猜測。請

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) 
end 
+0

我修改了上面的例子,刪除了可能導致混淆的域名。當我試圖對它進行基因化時,我錯過了它們。

你的建議,雖然看起來乾淨,但沒有奏效。我收到相同的錯誤消息。 – cwperry