For security reasons, you may want to store your attachment out of the public directory:
class DocumentVersion < ActiveRecord::Base
belongs_to :document
has_attached_file :version,
:path => ":rails_root/documents/:class/:id/:style/:basename.:extension"
...
end
To access this:
send_file(@document_version.version.path)
I found the directory defaults a little odd, so if you want to specify it:
class Picture < ActiveRecord::Base
has_attached_file :image,
:path => ":rails_root/public/images/pictures/:class/:id/:style/:basename.:extension",
:url => "/images/pictures/:class/:id/:style/:basename.:extension"
end
Note the :url parameter. If you set the path, you must set the :url accordingly. Of course, this only matters if you are going to call the url method.

0 comments:
Post a Comment