上传文件时权限被拒绝

时间:2019-01-12 14:45:35

标签: ruby-on-rails ruby-on-rails-5 paperclip

我正在建立一个新服务器,代码在显示此信息的服务器上的localhost上运行完美。

  

权限被拒绝@ dir_s_mkdir-private_data

我也尝试过enter code here,但它不起作用

  

chmod -R 777 private_data

在document.rb

class Document < ApplicationRecord
 has_attached_file :document,# styles: { :original => "512x512>"},
                    :styles => {
                        :medium => "512x512>",
                        :thumb => "345x215#",
                    },
                     default_url: "/images/:style/missing.png",
                    :url=>  :set_url,
                    :path =>:set_path
  VALID_IMAGE_TYPES = ["application/pdf",'image/gif', 'image/png', 'image/jpeg', 'image/jpg']

  validates_attachment :document, content_type: { content_type: VALID_IMAGE_TYPES, :message=>"File can be JPG, JPEG, PNG, PDF"}
  validates_attachment_size :document, :less_than => 8.megabytes,:message => "Your file size is larger than 7 MB, Read the instructions properly."


  private

  def set_url
    "/documents/document_viewer/:id/:style"
  end

  def set_path
    dept=Department.find(self.department_id).branch_name
    "private_data/document/#{dept}/:class/:attachment/:id_partition/:style/:filename"
  end
end

1 个答案:

答案 0 :(得分:0)

在下面使用:

chmod -R 777 PATH_TO_APP/uploads 
chmod -R 777 PATH_TO_APP/tmp 

应该有帮助。