This is an excellent question. Typical plugins that invoke before_ or
after_ style filters can be skipped using the skip_before_filter (for
example) construct. I don't know if attachment_fu supports this. It
would be worth testing, though.
It looks like in the source of attachment_fu, the class is extended
with (among other things):
base.after_validation :process_attachment
So maybe if you tell it to skip the validation on certain actions,
it'll skip the processing. I don't know if you can do:
validates_as_attachment, :only => :create
Most validates_ type calls support this, but looking at the source
code, I don't know if attachment_fu would. Worth fiddling with and
even monkeypatching attachment_fu if need be.
Another idea, and one that I use in my apps:
I have a model _just_ for images... i.e. in my case: Logo.
It only has the fields for images. Then, if I need the logo to be an
avatar for a person object, I simply have something like:
class Person < ActiveRecord::Base
belongs_to :avatar, :class_name => "Logo"
...
end
Then, when I create or update the person, I can redo the logo only if
it's got data... for example:
@logo = @person.build_logo(params[:logo]) unless params[:logo]
[:uploaded_data] == ""
@logo.valid? unless @logo.nil?
And for an update, I'd do:
@logo = @person.logo
@logo.destroy unless @logo.nil? or params[:logo]
[:uploaded_data].blank?
@logo = @person.build_logo(params[:logo]) unless params[:logo]
[:uploaded_data].blank?
@logo.valid? unless @logo.nil?
That way, if you update the person model and supply a new logo, it'll
destroy the old (which will delete the files as well as clear out the
DB record), then build a new one, and validate it so you have
validation checks.
At least this works for me. :-)
-Danimal
(btw, I need the "unless @logo.nil?" because nil.valid? causes an
exception)