[英]Permission denied @ dir_s_mkdir Error
我已经搜索了一段时间,但似乎找不到答案。
我正在使用回形针和Postgresql数据库上传和存储文件。
我得到的错误是:
Errno::EACCES in DocumentsController#create
Permission denied @ dir_s_mkdir - /documents
错误代码专门引用了文档控制器中的此部分:
def create
@document = current_user.documents.build(documents_params)
if @document.save
redirect_to @document
else
render 'new'
end
end
最近,我将数据库从sqlite切换到了postgresql,并且它可以在网上正常运行(我已经用heroku上传了它),但是还没有开发。
另外,我能够编辑和更新已经在开发中的文档,只是无法上传任何文档。
是否有任何配置文件或需要修改的内容才能获得@ dir_s_mkdir
大权限?
最后,我设法解决了这个问题。
因为我修改了数据库以在Heroku中使用PostgreSQL ,所以我还需要修改Document
模型,以适应生产和开发环境。
我还必须更改文档对象在development中分配给的:url
。 更新后的:url
变为:
: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
尽管更改文件/文件夹的所有权不是一个好选择,因为它将每个文件设置为任何人都可执行,可读和可写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.