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。
任何幫助,將不勝感激。