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
date>/: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
here>.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.

Looking for thoughts/help on how to access a field in another model in
this situation?

Thanks for any pointers - I am on 2.3.8.

-S

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to