From c5103d30250c0a5db1a21f9d0ff93e8aadd47a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 11 Jan 2022 16:54:41 +0100 Subject: [PATCH] Fix generating dashboard poster on production In commit 905ac48bb we mentioned: > Since we don't use `asset_path` to reference assets in the public > folder, we can safely disable the `unknown_asset_fallback` option. However, `asset_path` is used by the wicked_pdf gem when calling the `wicked_pdf_stylesheet_link_tag` method. This method also checks the CSS files, searching for `url()` calls and converting any relative URLs referenced there to absolute URLs. However, when compiling assets on production, our `application.css` file contains the following line imported from Leaflet which says: ``` behavior: url(#default#VML); ``` When passing this URL to `asset_path` (which is something the wicked_pdf gem does automatically), it doesn't find the URL, and so this call crashes unless we enable then `unknown_asset_fallback` option. Since the dashboard poster is a feature we might remove in the future, we're avoiding changing a Rails global configuration just for this feature. So, instead of enabling the `unknown_asset_fallback` option, we're changing the `poster.pdf` view so it doesn't load all the CSS of the application but only the CSS it needs. Note we aren't adding a test case because this bug is only present on production environments when assets have been precompiled. --- app/assets/config/manifest.js | 1 + app/assets/stylesheets/dashboard_poster.scss | 6 ++++++ app/views/dashboard/poster/index.pdf.erb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/dashboard_poster.scss diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index c952cc97e..56e14cf18 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -9,6 +9,7 @@ //= link ckeditor/config.js //= link stat_graphs.js //= link dashboard_graphs.js +//= link dashboard_poster.css //= link print.css //= link pdf_fonts.css //= link_tree ../../../vendor/assets/images diff --git a/app/assets/stylesheets/dashboard_poster.scss b/app/assets/stylesheets/dashboard_poster.scss new file mode 100644 index 000000000..620458dbd --- /dev/null +++ b/app/assets/stylesheets/dashboard_poster.scss @@ -0,0 +1,6 @@ +@import "font-awesome/variables"; +@import "font-awesome/mixins"; +@import "font-awesome/core"; +@import "foundation_and_overrides"; +@import "mixins/*"; +@import "dashboard"; diff --git a/app/views/dashboard/poster/index.pdf.erb b/app/views/dashboard/poster/index.pdf.erb index 220bb462e..c1ba4ea78 100644 --- a/app/views/dashboard/poster/index.pdf.erb +++ b/app/views/dashboard/poster/index.pdf.erb @@ -3,7 +3,7 @@ - <%= wicked_pdf_stylesheet_link_tag "application" -%> + <%= wicked_pdf_stylesheet_link_tag "dashboard_poster" -%> <%= wicked_pdf_stylesheet_link_tag "pdf_fonts" -%>