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.
Cheers,
Andy
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk