Paperclip – Customizing Paths and URLs
Posted on October 19, 2009
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
- Paperclip RDoc - http://dev.thoughtbot.com/paperclip/
- Paperclip Railscasts - http://railscasts.com/episodes/134-paperclip
- Jim Neath - Paperclip: Attaching Files in Rails - http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/

