【发布时间】:2013-05-16 21:13:47
【问题描述】:
我有一个返回哈希的方法:
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
但是没有正确创建索引。
我知道to_indexed_json 方法的methods 选项:
def to_indexed_json
to_json( methods: [:image_hash] )
end
哪个有效。但是如果不从头开始重新创建整个 JSON 对象,我看不到如何在该块中重新定义它。看起来偏好是完全将 mapping 块用于索引 JSON。
任何帮助将不胜感激。
【问题讨论】:
标签: ruby-on-rails json elasticsearch tire