Acts_as_ferret cross model index not updating

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) 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

A little bit of progress …

From this: 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… :frowning:

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.

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. [email protected]

Thanks! Worked a charm.