我们正在使用thinktank gem,并且无法索引模型关联,甚至是简单的关联。 例如,一个配置文件属于一个机构,它有一个名称 - 我们想要做的事情如下:
class Profile < ActiveRecord::Base #model associations define_index do indexes institution(:name), :as => :institution_name end end但那不起作用。 这一定很简单 - 我做错了什么?
We are using thinkingtank gem and having trouble indexing model associations, even simple ones. For example, a profile belongs to an institution, which has a name – we would like to do something like:
class Profile < ActiveRecord::Base #model associations define_index do indexes institution(:name), :as => :institution_name end endbut that doesn't work. This must be very simple – what am I doing wrong?
最满意答案
这个问题的一个可能的解决方案是添加一个方法将元素返回给索引。 对于profile.institution.name的情况:
# profile.rb # ... belongs_to :institution # ... define_index do indexes institution_name end def institution_name self.institution.name end # ...另外,Thinkingtank不支持“::as => ...”语法。
我也建议尝试一下Tanker: https : //github.com/kidpollo/tanker
问候。
阿德里安
a possible solution to this issue would be adding a method returning the element to index. For the profile.institution.name case:
# profile.rb # ... belongs_to :institution # ... define_index do indexes institution_name end def institution_name self.institution.name end # ...Also the ", :as => ..." syntax is not supported on thinkingtank.
I would also recommend giving a try to Tanker: https://github.com/kidpollo/tanker
Regards.
Adrian
更多推荐
gem,simple,associations,电脑培训,计算机培训,IT培训"/> <meta name="descr
发布评论