[英]Permission denied @ dir_s_mkdir Error
I've been searching around for a while now but can't seem to find the answer. 我已经搜索了一段时间,但似乎找不到答案。
I'm using paperclip and postgresql database to upload and store files. 我正在使用回形针和Postgresql数据库上传和存储文件。
The error I am getting is : 我得到的错误是:
Errno::EACCES in DocumentsController#create
Permission denied @ dir_s_mkdir - /documents
And the error code is specifically referring to this section in the documents controller: 错误代码专门引用了文档控制器中的此部分:
def create
@document = current_user.documents.build(documents_params)
if @document.save
redirect_to @document
else
render 'new'
end
end
I recently switched my database from sqlite to postgresql and it is working perfectly fine online (I have uploaded it with heroku), just not in development. 最近,我将数据库从sqlite切换到了postgresql,并且它可以在网上正常运行(我已经用heroku上传了它),但是还没有开发。
Also, I am able to edit and update documents that have been uploaded already in development, just not able to upload any. 另外,我能够编辑和更新已经在开发中的文档,只是无法上传任何文档。
Are there any config files or something that I need to modify to grand permission for @ dir_s_mkdir
? 是否有任何配置文件或需要修改的内容才能获得
@ dir_s_mkdir
大权限?
Finally I managed to fix this problem. 最后,我设法解决了这个问题。
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. 因为我修改了数据库以在Heroku中使用PostgreSQL ,所以我还需要修改
Document
模型,以适应生产和开发环境。
I also had to change the :url
that the document object was assigning to in development . 我还必须更改文档对象在development中分配给的
:url
。 The updated :url
became: 更新后的
:url
变为:
:url => "/system/documents/pdfs/:id/:basename.:extension"
Below is the updated document.rb
model (for the paperclip
section): 以下是更新的
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
Many answers I referred to were saying to use either: 我提到的许多答案都说要使用以下任一方法:
sudo chown -R username app_path
/* or */
chmod -R 777 PATH_TO_APP/uploads
/* or */
chmod -R 777 PATH_TO_APP/tmp
Although changing ownership of a file/folder is not a good option, as it sets every file as executable, readable, and writeable by anyone. 尽管更改文件/文件夹的所有权不是一个好选择,因为它将每个文件设置为任何人都可执行,可读和可写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.