Если вы можете поместить файлы куда-нибудь более постоянные, чем / tmp, хранение и доступ к загруженным файлам вне каталога public
возможны с использованием параметров: url и: path, а также с небольшой настройкойработа.
Пример, извлеченный из кода, который я недавно написал (он достаточно изменен, чтобы он не работал, если вы скопируете его дословно):
app/models/picture.rb
# Define the attachment
has_attached_file :image,
:styles => {:large => ["700", :jpg],
:thumb => ["100x100>", :gif]},
:url => "/asset/picture/:id/:style/:basename.:extension",
:path => ":base/picture/:id/:style/:basename.:extension"
config/initializers/storage.rb
# Configure common attachment storage
# This approach allows more flexibility in defining, and potentially moving,
# a common storage root for multiple models. If unneeded, just replace
# :base in the :path parameter with the actual path
Paperclip.interpolates :base do |attachment, style|
/path/to/persistent/storage
# A relative path from the Rails.root directory should work as well
end
app/controllers/pictures_controller.rb
# Make the attachment accessible
def asset
instance = Picture.find(params[:id])
params[:style].gsub!(/\.\./, '')
#check permissions before delivering asset?
send_file instance.image.path(params[:style].intern),
:type => instance.image_content_type,
:disposition => 'inline'
end
config/routes.rb
# Add the necessary route
match '/asset/picture/:id/:style/:basename.:extension', :to => 'pictures#asset'
app/views/pictures/show.html.erb
<% # Display the picture %>
<%= image_tag picture.image.url(:large) %>
Обратите внимание, что это весь синтаксис Rails 3.Чтобы использовать его в Rails 2.x, потребовалось бы несколько изменений, но, надеюсь, вы получите картину ...