With paperclip, how can I change the image location to a ":parent_model_id/:id" folder format?

Posted by Jamis Charles on Stack Overflow See other posts from Stack Overflow or by Jamis Charles
Published on 2010-12-28T13:11:30Z Indexed on 2010/12/29 12:54 UTC
Read the original article Hit count: 135

Given that I have a Listing model that has many images and each image has one attachment, how can I have the listing_id be part of the folder structure?

Like so: system/photos/[listing_id]/:id

I know that using :id will output the id of the image record.

Here's what I currently have:

class Image < ActiveRecord::Base
belongs_to :listing #Rails ActiveRecord Relation. An image belongs to a post. 

# paperclip data
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :url => "/public/system/:class/:attachment/:id/:style_:filename"

end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-plugins