Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Add some more documentation for passing symbol to :url, :default_url,…
Browse files Browse the repository at this point in the history
… :path
  • Loading branch information
sikachu committed Sep 23, 2011
1 parent 996ca87 commit 1738f3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/paperclip.rb
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/paperclip/interpolations.rb
Expand Up @@ -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|
Expand Down

0 comments on commit 1738f3c

Please sign in to comment.