On Tue, Oct 31, 2006 at 07:47:30PM +0100, Andreas Korth wrote: > > On 31.10.2006, at 18:02, John Mcgrath wrote: > > > Hi, I'm using Rails/AAF with Ferret 0.10.11, and my index occasionally > > (every few weeks, roughly) becomes corrupted. > > > > If the index is busted, until I rebuild it our users are unable to > > save > > anything. I get errors like the one below, and the save rolls back. > > The acts_as_ferret plugin employs ActiveRecord callbacks such as > after_update to index the models. If an exception is thrown inside a > callback method, the action is rolled back. > > > My question is, is there any way to catch the error, and continue with > > the save even if the model isn't indexed? > > Several ways. You could overwrite the save mehtod (either on a per- > model-basis or for ActiveRecord::Base) to read: > > def save > begin > create_or_update > rescue => any_exception > # deal with exceptions you can handle or re-raise > end > end > > Or, even better, you could patch the acts_as_ferret code to resort to > a callback such as "rescue_error_in_ferret". See the 'ferret_create' > method of 'acts_as_ferret/lib/instance_methods.rb'. You'd basically > wrap the method in a begin/rescue block and see if the model > respond_to? :rescue_error_in_ferret. If it does, call that method or > else re-raise the exception.
overwriting the callback handlers in your model would be another possibility: class MyModel < AR::Base acts_as_ferret ... # ferret_create is declared by aaf, and used for before_update and # before_create events. alias :old_ferret_create :ferret_create def ferret_create old_ferret_create rescue # handle the error... true # tell AR everything is fine end end Jens -- webit! Gesellschaft für neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Krämer [EMAIL PROTECTED] Schnorrstraße 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66 _______________________________________________ Ferret-talk mailing list Ferret-talk@rubyforge.org http://rubyforge.org/mailman/listinfo/ferret-talk