Search code examples
ruby-on-railsattachment-fu

Uploading a file to a directory outside of RAILS ROOT with attachment_fu


I'm trying to use attachment_fu to upload files to a directory outside of the RAILS_ROOT. I want the files to be saved to ~/APP_NAME/uploads/ so that they can be approved/rejected before becoming publicly available. I've tried the following configuration for has_attachment:

has_attachment  :storage => :file_system,
                :path_prefix => "~/APP_NAME/uploads/",
                :max_size => 5.megabytes

Unfortunately, this configuration simply creates the ~/APP_NAME/uploads/ directory structure in RAILS_ROOT. Any way to save the file outside of RAILS_ROOT?


Solution

  • I found an alternative method that suits me better than using relative pathnames. I added a method called full_filename to my attachment class:

    class attachment < ActiveRecord::Base
        def full_filename
           return  "/Users/ron/attachments/#{id}.#{file_format}"
        end
    end