AssetManager Controlling Where Files are Saved

I wanted to put this out there to possibly help someone and also to
get any feedback if this is the wrong way to do it…

By default the AssetManager saves uploaded files in public/assets/ID/

I wanted files to be saves in the public/images directory.

To do that edit asset.rb the acts_as_attachment line to be:

acts_as_attachment :storage => :file_system, :file_system_path =>
‘public/images’,
:max_size => 2048.kilobytes, :content_type => :image,
:thumbnails => { :normal => ‘600x400’, :thumbnail => ‘100x100’, :icon
=> ‘42x42’ }

Note I added:
“:file_system_path => ‘public/images’,”

This got the images saved in the public/images directory however it
still created a directory for the ID so images were stored like
public/images/3/*.jpg

To get them in the ‘images’ directory override the “full_filename”
method to asset.rb:

def full_filename(thumbnail = nil)
file_system_path = (thumbnail ? thumbnail_class :
self).attachment_options[:file_system_path]
#File.join(RAILS_ROOT, file_system_path,
attachment_path_id,thumbnail_name_for(thumbnail))
File.join(RAILS_ROOT, file_system_path, thumbnail_name_for(thumbnail))
end

Note I commented out the first File.join line and aded a new one minus
the “attachment_path_id”

Hope this helps and again if this is a bad idea someone please tell me!

Thanks-
Michael