Skip to content

Commit ffd6ad4

Browse files
committed
Hotfix for PDF CSS not loading properly
1 parent 1876af4 commit ffd6ad4

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

app/views/layouts/pdf.html.erb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,29 @@
44
<html>
55
<head>
66
<title><%= yield(:title) %></title>
7-
<% app_css_path = Rails.root.join('app', 'assets', 'builds', 'application.css') %>
8-
<% css = File.exist?(app_css_path) ? File.read(app_css_path) : '' %>
7+
<%
8+
# Load CSS from both app/assets/builds (development) and public/assets (production/staging)
9+
css = ''
10+
candidates = []
11+
12+
# Add CSS from app/assets/builds (development)
13+
candidates.concat(Dir.glob(Rails.root.join('app', 'assets', 'builds', '*.css').to_s))
14+
15+
# Add CSS from public/assets (production/staging with fingerprinted names)
16+
candidates.concat(Dir.glob(Rails.root.join('public', 'assets', 'application-*.css').to_s))
17+
18+
# Read and combine all CSS files
19+
css = candidates.filter_map do |path|
20+
begin
21+
File.read(path)
22+
rescue => e
23+
Rails.logger.warn "Could not read compiled CSS from #{path}: #{e.message}"
24+
nil
25+
end
26+
end.join("\n")
27+
28+
Rails.logger.warn "No CSS files found for PDF generation" if css.blank?
29+
%>
930
<style type="text/css">
1031
<%= css.html_safe %>
1132
</style>

0 commit comments

Comments
 (0)