# Acts\_as\_ferret cross model index not updating

**URL:** <https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352>\
**Category:** Rails\
**Created:** [August 6, 2007, 1:11pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352 "2007-08-06T13:11:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![piers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@piers](https://www.ruby-forum.com/u/piers)\
**Post date:** [August 6, 2007, 1:11pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352/1 "2007-08-06T13:11:34Z")

</div>

Does anyone know how do you get acts\_as\_ferret to automagically update  
non-standard fields?

I’ve followed Rails Envy’s tutorial  
([http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial#nonmodel](http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial#nonmodel)) to  
get aaf working across different models. And once the index is built it  
searches fine.

In my (main) model, I’ve put:

acts\_as\_ferret :fields =\> [ :name,  
:notes,  
:ferret\_cat,  
:ferret\_comments,  
:ferret\_place,  
:ferret\_postcode,  
:ferret\_bookmarks,  
:ferret\_tags]

and e.g.

def ferret\_cat  
return “#{self.category.name}”  
end

But if I update any of the other models, by adding a comment or  
bookmarking etc, the index doesn’t update.

Does someone know how I can get these non-model fields to update?

Thanks  
Piers

---

<div class="post-metadata">

**Author:** ![piers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@piers](https://www.ruby-forum.com/u/piers)\
**Post date:** [August 6, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352/2 "2007-08-06T17:12:02Z")

</div>

A little bit of progress …

From this: [http://www.ruby-forum.com/topic/96162](http://www.ruby-forum.com/topic/96162) it seems that adding  
@item.ferret\_update should index the changes in the associated models.

Still not working though… ☹

---

<div class="post-metadata">

**Author:** ![piers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@piers](https://www.ruby-forum.com/u/piers)\
**Post date:** [August 7, 2007, 1:51pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352/3 "2007-08-07T13:51:46Z")

</div>

Just add an after\_save callback any associated models to cause a  
reindex.  
Eg:.

class Post \< AR::Base  
acts\_as\_ferret :fields =\> :category\_name

def category\_name  
category.name if category  
end  
end

class Category \< AR::Base  
after\_save do |category|  
if category.post  
category.post.ferret\_update  
end  
end  
end

-Jonathan.

---

<div class="post-metadata">

**Author:** ![piers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@piers](https://www.ruby-forum.com/u/piers)\
**Post date:** [August 9, 2007, 6:58am UTC](https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352/4 "2007-08-09T06:58:03Z")

</div>

Reading your post i got an idea to write a rake task to use  
Model.rebuild\_index  
acts\_as\_ferret…  
this way i can rebuild the index for all my nonstandard fields to get  
reindexed… whenever i want…  
thanks…

On Aug 8, 5:03 am, Piers Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![piers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@piers](https://www.ruby-forum.com/u/piers)\
**Post date:** [August 7, 2007, 9:03pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-cross-model-index-not-updating/111352/5 "2007-08-07T21:03:17Z")

</div>

Thanks! Worked a charm.
