diff --git a/lib/paperclip.rb b/lib/paperclip.rb index 1c782b4b8..09bd8acbd 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -291,6 +291,20 @@ module ClassMethods # choices are :filesystem and :s3. The default is :filesystem. Make sure you read the # documentation for Paperclip::Storage::Filesystem and Paperclip::Storage::S3 # for backend-specific options. + # + # It's also possible for you to dynamicly define your interpolation string for :url, + # :default_url, and :path in your model by passing a method name as a symbol as a argument + # for your has_attached_file definition: + # + # class Person + # has_attached_file :avatar, :default_url => :default_url_by_gender + # + # private + # + # def default_url_by_gender + # "/assets/avatars/default_#{gender}.png" + # end + # end def has_attached_file name, options = {} include InstanceMethods diff --git a/lib/paperclip/interpolations.rb b/lib/paperclip/interpolations.rb index f34c978b5..f05d204f5 100644 --- a/lib/paperclip/interpolations.rb +++ b/lib/paperclip/interpolations.rb @@ -25,7 +25,8 @@ def self.all # Perform the actual interpolation. Takes the pattern to interpolate # and the arguments to pass, which are the attachment and style name. - # You can pass a :symbol as pattern assigning some method in your model class. + # You can pass a method name on your record as a symbol, which should turn + # an interpolation pattern for Paperclip to use. def self.interpolate pattern, *args pattern = args.first.instance.send(pattern) if pattern.kind_of? Symbol all.reverse.inject( pattern.dup ) do |result, tag|