Indexing Method Results in ElasticSearch from Associated ActiveRecord Objects

I am following the example here for indexing ActiveRecord objects and associated objects in Elasticsearch.
https://gist.github.com/karmi/3200212

Is there anything else that I would need to take into account if the associated object is storing the results of a method? I'm actually using the acts-as-taggable-on gem with tag_list. My to_indexed_json looks like this guy:

to_json(include: { items: {only: :name, methods: :tag_list} })

When I rebuild with the following,

rake environment tire:import CLASS=Business FORCE=true

it successfully included the results of tag_list for each Item.

Following the example, Business does a tire.update_index after being touched. However, when I add a new "Item," it successfully adds all the attributes of said Item but without the tag_list.

Here's a link to my two models: https://gist.github.com/grumpasuarus/6661414


In the end, I wasn't understanding how the to_json method worked with "methods: :tag_list".

In order for that to work, I needed a method "tag_list" at my Business model.

To ultimately resolve the issue, I created a method in the Business model to get me all the tagging information for given item.

链接地址: http://www.djcxy.com/p/36026.html

上一篇: 行为简单的形式自定义输入

下一篇: 索引方法从关联的ActiveRecord对象导出ElasticSearch