【问题标题】:Permission denied @ dir_s_mkdir Error权限被拒绝@dir_s_mkdir 错误
【发布时间】:2016-12-28 16:27:56
【问题描述】:

我已经搜索了一段时间,但似乎找不到答案。

我正在使用回形针和 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 的高级权限的内容?

【问题讨论】:

    标签: ruby-on-rails postgresql sqlite heroku


    【解决方案1】:

    我终于设法解决了这个问题。

    • 因为我修改了我的数据库以将 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
    

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

    【讨论】:

      猜你喜欢
      • 2017-06-28
      • 2015-07-20
      • 2016-03-14
      • 2016-05-07
      • 1970-01-01
      • 2018-12-13
      • 2016-01-19
      • 2015-12-06
      • 2015-12-18
      相关资源
      最近更新 更多