SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

Rails Paperclip Plugin Options for Attaching Files

       

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 w/ #avatars #file uploads #options #paperclip #pluginsruby on rails

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app