Paperclip custom Interpolation in url

Folks,

I have a simple model hierarchy (reduced to example as below)

class Post < ActiveRecord::Base      has_many :comments end

class Comment < ActiveRecord::Base      belongs_to :post   has_attached_file :photo,       # :url => "/assets/class_cal/<original post

/:id/:style/:basename.:extension"

  :url => "/assets/post/:post_date/:id/:style/:basename.:extension" end

What I want to do: I am trying to insert the "original post date" in the url with the :post_date (stored in the Post model) interpolation function as defined in the Paperclip Interpolation module below.

-------------------------------------------- module Paperclip module Interpolations def post_date attachment, style_name attachment.<access the post class/model >.instance_read(:post_date).to_s end end end -------------------------------------------------

Problem: The problem I am running into is that I can't seem to access the post model object from the definition of post_date function above - the attachment I understand refers to the Comment object. I have tried attachment.post.instance_read(:post_date) but that doesn't work.

isn't attachment.instance what gives you the associated AR object (ie attachment.instance.post would be what you are looking for here) ?

Fred