Paperclip – Customizing Paths and URLs
Oct 19, 2009
1 minute read

To customize the paths and urls of paperclip objects in your rails app you need to modify both the :path and :url options for  has_attached_file in your models. Here’s an example…

``

`

class SomeModel < ActiveRecord::Base
 
  has_attached_file :image_one,
    :path => "public/system/:class/:id/:filename",
    :url => "/system/:class/:id/:basename.:extension"
 
  has_attached_file :image_two,
    :path => "public/system/:class/:id/:filename",
    :url => "/system/:class/:id/:basename.:extension"
end

`

By default Paperclip will store your files in /system/:attachment/:id/:style/:filename. By passing the :path and :url options to the has_attached_file method in your model you can change where the uploaded files will be stored as well as where they can be accessed. The :path is the directory in your application where your files will be stored. The :url is the url that users will use to render the image.

Paperclip Resources