简体   繁体   中英

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

I'm getting this error in Unicorn.log when trying to attach files with paper clip on my ubuntu virtual server app:

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'

In the controller I have

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

If this info is not enough please comment where else the issue could reside, and I'll happily share more code.

Solved it. The problem was that the user that handles Rails on the virtual server didn't have all the access needed to generate files on behalf of paperclip in the app's folder. So I gave larger access to the folder using this terminal command:

$ sudo chmod -R 775 /RailsAppFolder

Try to replace

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

with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM