Hi,
I have a photos model that has_many comments. When the photo is saved,
it builds the comments into a string that is indexed.
When the comments are saved, it needs to re-index the comments from the
photo model. The way I do it is by calling self.photo.save on the
after_save method of the comments model.
This seems botchy, is there a better way?
class Photo < ActiveRecord::Base
has_many :comments
acts_as_ferret :fields => [:title, :photo_comments], :remote => true
def photo_comments
comments.collect{|c| c.comment}.join(’ ')
end
end
class Comment < ActiveRecord::Base
belongs_to :account, :counter_cache => true
belongs_to :photo, :counter_cache => true
validates_presence_of :comment
def after_save
self.photo.save
end
end
Thanks,
Tim