Rails PaperClip Errno::EACCES(权限被拒绝@dir_s_mkdir - ~rails

Rails PaperClip Errno::EACCES (Permission denied @ dir_s_mkdir - ~rails

我在 Unicorn.log 中尝试在我的 ubuntu 虚拟服务器应用程序上使用回形针附加文件时遇到此错误:

Completed 500 Internal Server Error in 312ms (ActiveRecord: 10.1ms)

Errno::EACCES (Permission denied @ dir_s_mkdir - ~rails):
  app/controllers/articles_controller.rb:30:in `block in create'
  app/controllers/articles_controller.rb:29:in `create'

在我的控制器中

class Article < ActiveRecord::Base
    has_attached_file :img,
    url: "/system/:attachment/:id/:style/:filename",
    validates_attachment_content_type :img, content_type: /\Aimage\/.*\Z/
end

如果此信息不够,请评论问题可能存在的其他地方,我很乐意分享更多代码。

尝试替换

path: "~rails/umbertoputzu/public/system/:attachment/:id/:style/:filename",

path: "~/rails/umbertoputzu/public/system/:attachment/:id/:style/:filename",

解决了。问题是在虚拟服务器上处理 Rails 的用户没有代表应用程序文件夹中的回形针生成文件所需的所有访问权限。因此,我使用此终端命令授予了对该文件夹的更大访问权限:

$ sudo chmod -R 775 /RailsAppFolder