2013-05-16 42 views
0

我有一個返回哈希方法:在輪胎映射塊訪問方法/ elasticsearch

def image_hash 
    images = { 
    small: 'http://www.example.com/image1.png', 
    medium: 'http://www.example.com/image2.png' 
    } 
end 

我需要索引它作爲輪胎加載ActiveModel映射的一部分,但我不能讓它與合作indexes方法中的as:選項。

的問題是,我需要重新定義它爲圖片(這是另一個模型法),所以我想它像這樣:

indexes :image_hash, as: :images do 
    indexes :small, type: 'string', include_in_all: false 
end 

但沒有被正確創建索引。

我知道methods選項爲to_indexed_json方法:

def to_indexed_json 
    to_json(methods: [:image_hash]) 
end 

其中一期工程。但我無法看到如何在該塊中重新定義它,而無需從頭開始重新創建整個JSON對象。它也看起來像是完全使用mapping塊爲索引的JSON。

任何幫助,將不勝感激。

回答

0

我真的不知道你想要做什麼有,但你不能動態獲取一個項目出來的哈希值,如果這就是你想要做

你可能想用什麼類型的對象,所以你可以只存儲整個具有直接

indexes :image_hash, type: object, include_in_all: false 

應該足夠