Search code examples
ruby-on-railsrubymodel-view-controllerattachment-fu

Being as DRY as possible in a Ruby on Rails App


I'm currently using the awesome attachment-fu plugin for a Rails app, but as a novice developer, I've never encountered a scenario like the one I've found myself in.

Essentially, I'm using the attachment-fu plugin on two levels.

  1. Is for user avatars in the user class.
  2. Is to allow file attachments (PDFs, etc) in a messaging system.

My question is what the best use practice would be in these situations to remain DRY, clear, and consistent.

Clearly it would make no sense to define and execute the plugin in both classes, but there's something deeply strange to me (possibly unfounded) about just going ahead and setting it all up in the godly Application class.

Is there something in between, or is the parent class the way to go?

Thanks!


Solution

  • I would lean towards using a parent class, with subclassing for the different ways you intend to actually use the attachments in your application. It may not be the DRYest solution available, however, it lends itself to a logical pattern rather well.