vhochstein / active_scaffold

Rails 4 Version of activescaffold supporting jquery
MIT License
156 stars 34 forks source link

Paperclip bridge helper overwrites existing methods #160

Closed robg closed 13 years ago

robg commented 13 years ago

This fixes the conditional guard to check against instance methods rather than class methods before defining the delete_attachment methods.

vhochstein commented 13 years ago

Can you please explain why it s better to check for instance_methods?

robg commented 13 years ago

I'm guessing the reason for this guard is so that the helper isn't overwriting any existing methods. Since it is defining an instance method, it makes sense to check there rather than at the class level. If I add some logging to this block, you can see that the class level check is pretty ineffective. In this scenario, my Company model has already defined a delete_logo method for its logo attachement:

Generating Paperclip delete methods for logo in Company
Klass method defined: false
Klass instance method defined: true
After Paperclip delete method defined for logo in Company
Klass method defined: false
Klass instance method defined: true