title: Dynamic use of :default_url in Paperclip
body: <p>I'm trying to configure Paperclip to provide different missing images based on the instance's category attribute. Every category of the object has its own missing image.</p>
  
  <p>This is my first take:</p>
  
  <p>EDIT to add full models:</p>
  
  <pre><code>class Service &lt; ActiveRecord::Base
  
    attr_accessible :logo, :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at
  
    belongs_to :category, :counter_cache =&gt; true
  
    has_attached_file :logo,
                  :path =&gt; "/:id-:style-:filename",
                  :url  =&gt; ":s3_eu_url",
                  :default_url =&gt; "/logos/:style/#{self.category.name]}.png",
                  :styles =&gt; { :large =&gt; "600x400&gt;",
                               :medium =&gt; "300x200&gt;",
                               :small =&gt; "100x75&gt;",
                               :thumb =&gt; "60x42&gt;" }
  end
  
  class Category &lt; ActiveRecord::Base
    attr_accessible nil
  
    has_many :services
  end
  </code></pre>
  
  <p>In my view, <code>image_tag service.logo.url(:thumb)</code> outputs: </p>
  
  <pre><code>undefined method `category' for #&lt;Class:0x0000010a731620&gt;
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>EDIT2:</p>
  
  <p>A working default_url is <code>:default_url =&gt; "/logos/:style/missing.png",
  </code></p>
  
  <h2>SOLUTION:</h2>
  
  <p>See my own answer below.</p>