I've been searching around for a while now but can't seem to find the answer.
I'm using paperclip and postgresql database to upload and store files.
The error I am getting is :
Errno::EACCES in DocumentsController#create
Permission denied @ dir_s_mkdir - /documents
And the error code is specifically referring to this section in the documents controller:
def create
@document = current_user.documents.build(documents_params)
if @document.save
redirect_to @document
else
render 'new'
end
end
I recently switched my database from sqlite to postgresql and it is working perfectly fine online (I have uploaded it with heroku), just not in development.
Also, I am able to edit and update documents that have been uploaded already in development, just not able to upload any.
Are there any config files or something that I need to modify to grand permission for @ dir_s_mkdir
?
Finally I managed to fix this problem.
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"
Below is the updated document.rb
model (for the paperclip
section):
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
Many answers I referred to were saying to use either:
sudo chown -R username app_path
/* or */
chmod -R 777 PATH_TO_APP/uploads
/* or */
chmod -R 777 PATH_TO_APP/tmp
Although changing ownership of a file/folder is not a good option, as it sets every file as executable, readable, and writeable by anyone.
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.