# Acts\_as\_ferret extra (polymorphic) fields

**URL:** <https://www.ruby-forum.com/t/acts-as-ferret-extra-polymorphic-fields/122741>\
**Category:** Rails\
**Created:** [December 11, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-extra-polymorphic-fields/122741 "2007-12-11T16:04:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunopreis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brunopreis](https://www.ruby-forum.com/u/brunopreis)\
**Post date:** [December 11, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-extra-polymorphic-fields/122741/1 "2007-12-11T16:04:32Z")

</div>

Hi,

I have a class with some polymorphic associations to it. I want to use  
acts\_as\_ferret to index my objects and its associations. I want to do  
it in a way I can define the fields from the associations to be  
indexed in the association class.

I know I could do something like:

acts\_as\_ferret :fields =\> [:title, :body, :author\_name]  
has\_one :author

def author\_name  
author.name  
end

but since the relationship is polymorphic it woul be like

acts\_as\_ferret :fields =\> [:title, :body, :extra\_field]  
belongs\_to :extra, :polymorphic=\>true

def extra\_field  
case self.extra\_type  
when ‘x’  
x.name  
when ‘y’  
y.date  
end

what is very ugly and realy not DRY. How can I define in the foreing  
class the fields to be indexed?

thanks for any answers! acts\_as\_ferret seems to be very nice, but I  
fell it lacks some docs.

Bruno
