I have installed wicked_pdf on my rails 4 project. I have it running under nginx and passenger on my Ubuntu 16 EC2 machine.
When i try to generate a PDF in 'production' i get the following error:
ActionView::Template::Error (Permission denied @ dir_s_mkdir - /.../tmp/cache):
Off course it will work if i chmod -R 777 my tmp folder but i don't want to fix it in this way.
While searching i've found that i should chown the folder to www-data user; i've tried it without luck, maybe the process that generates the PDF should have permission over this folder?
Thanks in advance
Edit, added the trace:
App 17963 stdout: ***************WICKED***************
App 17963 stdout: Rendered posts/article.pdf.erb within layouts/article_pdf.html.erb (0.9ms)
App 17963 stdout: Completed 500 Internal Server Error in 34ms (ActiveRecord: 6.5ms)
App 17963 stdout:
App 17963 stdout: ActionView::Template::Error (Permission denied @ dir_s_mkdir - xxx/.../tmp/cache):
App 17963 stdout: 3: <head>
App 17963 stdout: 4: <title></title>
App 17963 stdout: 5: <%= stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" %>
App 17963 stdout: 6: <%= wicked_pdf_stylesheet_link_tag 'application' %>
App 17963 stdout: 7: <%= wicked_pdf_stylesheet_link_tag 'social' %>
App 17963 stdout: 8: <%= wicked_pdf_stylesheet_link_tag 'directories' %>
App 17963 stdout: 9: <%= wicked_pdf_stylesheet_link_tag 'home' %>
App 17963 stdout: app/views/layouts/article_pdf.html.erb:6:in `_app_views_layouts_article_pdf_html_erb__3815099653923299167_60691780'
App 17963 stdout: app/controllers/posts_controller.rb:167:in `block (2 levels) in article'
App 17963 stdout: app/controllers/posts_controller.rb:164:in `article'
App 17963 stdout:
App 17963 stdout:
App 17963 stdout: Processing by ErrorsController#internal_server_error as PDF
Edit 2: This error comes up each time i precompile my assets and restart my nginx server. It seems that each time i precompile my assets the tmp folder content is recreated by root.
I think that you should grant the permissions for user that run Passenger or sidekiq. To find that user you can use below command:
ps -aux | grep "sidekiq\|Passenger"
Edit (Update the root cause):
The root cause is that wicket_pdf detect that it should precompile assets while in production, assets are already precompiled and it shouldn't try to compile them anymore.
Set assets.compile
to true
force wicket_pdf to use precompiled ones. The code to check whether it should use compiled assets or not is here.