2013-05-16 55 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 

应该足够