Dynamic use of :default_url in Paperclip
- by dgilperez
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.
This is my first take:
EDIT to add full models:
class Service < ActiveRecord::Base
attr_accessible :logo, :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at
belongs_to :category, :counter_cache => true
has_attached_file :logo,
:path => "/:id-:style-:filename",
:url => ":s3_eu_url",
:default_url => "/logos/:style/#{self.category.name]}.png",
:styles => { :large => "600x400>",
:medium => "300x200>",
:small => "100x75>",
:thumb => "60x42>" }
end
class Category < ActiveRecord::Base
attr_accessible nil
has_many :services
end
In my view, image_tag service.logo.url(:thumb) outputs:
undefined method `category' for #<Class:0x0000010a731620>
Any ideas?
EDIT2:
A working default_url is :default_url => "/logos/:style/missing.png",
SOLUTION:
See my own answer below.