最终我成功解决了这个问题。
Because I had modified my database to use PostgreSQL with Heroku I needed to also modify my Document
model, to accomodate for both production and development environments.
I also had to change the :url
that the document object was assigning to in development. The updated :url
became:
:url => "/system/documents/pdfs/:id/:basename.:extension"
以下是更新的
document.rb
模型(针对
paperclip
部分):
if Rails.env.development?
has_attached_file :pdf, :use_timestamp => false,
:url => "/system/documents/pdfs/:id/:basename.:extension",
:path => ":rails_root/public/system/documents/pdfs/:id/:basename.:extension"
validates_attachment_content_type :pdf, :content_type => ["application/pdf","application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"]
else
has_attached_file :pdf, :use_timestamp => false
validates_attachment_content_type :pdf, :content_type => ["application/pdf","application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"]
end
我参考的许多答案都建议使用以下方法之一:
sudo chown -R username app_path
/* or */
chmod -R 777 PATH_TO_APP/uploads
/* or */
chmod -R 777 PATH_TO_APP/tmp
虽然更改文件/文件夹的所有权并不是一个好选择,因为它会将每个文件都设置为可执行、可读和可写,任何人都可以访问。