权限被拒绝@dir_s_mkdir错误

3

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

我正在使用paperclip和postgresql数据库上传和存储文件。

我收到的错误消息是:

在DocumentsController#create中出现Errno::EACCES错误

无法访问目录/documents

而这个错误代码特别指向了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权限?

1个回答

2

最终我成功解决了这个问题。

  • 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.

  • I also had to change the :url that the document object was assigning to in development. The updated :url became:

    :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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接