# How to update index with acts\_as\_ferret?

**URL:** <https://www.ruby-forum.com/t/how-to-update-index-with-acts-as-ferret/105037>\
**Category:** Ferret\
**Created:** [May 25, 2007, 4:27am UTC](https://www.ruby-forum.com/t/how-to-update-index-with-acts-as-ferret/105037 "2007-05-25T04:27:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [May 25, 2007, 4:27am UTC](https://www.ruby-forum.com/t/how-to-update-index-with-acts-as-ferret/105037/1 "2007-05-25T04:27:54Z")

</div>

Hey all,  
I have movie has\_many :medias and media belongs\_to :media

this is how my movie class looks like:

class Movie \< ActiveRecord::Base  
has\_many :medias

acts\_as\_ferret :fields =\> [:title,:medias\_name]

def medias\_name  
return self.medias.inject("") {|name,m| name + " " + m.name}  
end

end

when I do Movie.find\_by\_contents(“title:bob”) it does return a movie  
and if I modify that movie title to Bill and do  
Movie.find\_by\_contents(“title:bill”) it will return the movie also.

But if I create a new media xyz and try to search on it  
Movie.find\_by\_contents(“medias\_name:xyz”) it doesn’t find it, I need  
to rm -rf index/ and restart the server to make it find it. Any idea  
how I can update the index on special fields?

thanx in advance

Pat

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [May 26, 2007, 11:57am UTC](https://www.ruby-forum.com/t/how-to-update-index-with-acts-as-ferret/105037/2 "2007-05-26T11:57:47Z")

</div>

Hi!

On Fri, May 25, 2007 at 04:27:35AM +0200, Patrick A. wrote:

> def medias\_name  
> Movie.find\_by\_contents(“medias\_name:xyz”) it doesn’t find it, I need  
> to rm -rf index/ and restart the server to make it find it. Any idea  
> how I can update the index on special fields?

you can’t update single fields, you havbe to reindex that movie to  
reflect the changes. An after\_save hook in media calling  
movie.ferret\_update should do the trick.

Jens

–  
Jens Krämer  
webit! Gesellschaft für neue Medien mbH  
Schnorrstraße 76 | 01069 Dresden  
Telefon +49 351 46766-0 | Telefax +49 351 46766-66  
removed\_email\_address@domain.invalid | [www.webit.de](http://www.webit.de)

Amtsgericht Dresden | HRB 15422  
GF Sven Haubold, Hagen Malessa
