简体   繁体   English

Rails 4.2.0 - Errno :: EACCES(权限被拒绝@dir_s_mkdir - / files)

[英]Rails 4.2.0 - Errno::EACCES (Permission denied @ dir_s_mkdir - /files)

In rails 4.2.0, I am using paperclip for file uploads. 在rails 4.2.0中,我使用paperclip进行文件上传。 But it is throwing an error like Errno::EACCES (Permission denied @ dir_s_mkdir - /files) , how can I fix this issue? 但它抛出了像Errno::EACCES (Permission denied @ dir_s_mkdir - /files)这样的错误,我该如何解决这个问题呢?

When I run gem list paperclip , I got the list like below 当我运行gem list paperclip ,我得到了如下所示的列表

paperclip (4.3.0, 4.2.2, 4.2.0, 2.4.5)

In controller, I have tried 2 ways, one is @file = Asset.new(:document=>params[:asset][:document]) and the other way is 在控制器中,我尝试了两种方法,一种是@file = Asset.new(:document=>params[:asset][:document]) ,另一种方式是

@file = Asset.new(user_params)

def user_params
  params.require(:asset).permit(:document)
end 

In model, 在模型中,

attr_accessible :status, :document_file_name, :document_content_type, :document_file_size
attr_accessible :document

has_attached_file :document,
:url => '/files/:assetable_id/:basename.:extension',
:path => "/files/:assetable_id/:basename.:extension",
:storage => :filesystem

How can I solve this permission denied issue? 如何解决此权限被拒绝的问题?

Change your path to the following (using :rails_root ): 将路径更改为以下(使用:rails_root ):

:path => ":rails_root/files/:assetable_id/:basename.:extension"

rails_root will give you the path to your app. rails_root将为您提供应用程序的路径。

To create Directory on local drive here is the running code- To do so I was executing- 要在本地驱动器上创建目录,这里是正在运行的代码 - 为此,我正在执行 -

Dir.mkdir(Rails.root+ '/' + 'export')

But getting error as- Errno::EACCES: Permission denied @ dir_s_mkdir - /Main_File 但得到错误as- Errno :: EACCES:Permission denied @ dir_s_mkdir - / Main_File
I know what was the reason, it was looking for Super User ( $ sudo ) permission but we can't provide machine password each time. 我知道是什么原因,它正在寻找超级用户( $ sudo )权限,但我们每次都无法提供机器密码。

Following worked for me as required- 以下按要求为我工作 -

Dir.mkdir(File.join(Dir.home, ".foo"), 0700) #=> 0

To create and store the path in a variable- 在变量中创建和存储路径 -

main_file = File.exist?( File.join(Dir.home, "Main_File") ) ? File.join(Dir.home, "/Main_File") : Dir.mkdir( File.join(Dir.home, "Main_File") )

Above will create file if doesn't exist 如果不存在,上面将创建文件
If it exist will access that and store in variable main_file . 如果它存在将访问它并存储在变量main_file

Thanks for this link ! 谢谢你的链接

Hope will work for you ! 希望对你有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM