2016-08-22 263 views
2

我一直在寻找一段时间,但似乎无法找到答案。权限被拒绝@ dir_s_mkdir错误

我使用paperclip和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

回答

0

最后我设法解决了这个问题。

  • 因为我修改了我的数据库使用PostgreSQL的的Heroku我需要同时修改了我的Document模型,以适应为生产和开发环境。

  • 我还必须更改文档对象分配给开发: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 

尽管更改文件/文件夹的所有权不是一个好的选择,因为它将每个文件设置为可执行,可读和任何人都可写。