Written by Sean Behan on Sun Jun 17th 2012

I usually change some of the default settings when I use the Paperclip plugin. For most of my projects I don't like having separate directories for each image that is uploaded. I prefer, in this instance, to put avatars of different sizes together under one directory and differentiated based on the style size of the image. To do this just set the path and url options like so...

  has_attached_file :avatar,
    :styles => {:thumb => "75x75", :medium => "150x150", :large => "500x500"},
    :default_url => "/images/default_avatar.png",
    :url => "/system/avatars/:id/:style_:basename.:extension",
    :path => ":rails_root/public/system/avatars/:id/:style_:basename.:extension"

Also, when you set up the database your model will need to have the following columns for Paperclip to work properly

      t.column :avatar_file_name, :string
      t.column :avatar_content_type, :string
      t.column :avatar_file_size, :integer

Don't forget that to handle file uploads in Rails you need to set the form with

form_for current_user, :html =>{:multipart => true} do |f|
Otherwise, your upload won't work :(

Tagged with..
#avatars #file uploads #options #paperclip #plugins #Ruby on Rails

Just finishing up brewing up some fresh ground comments...