Skip to content

Commit

Permalink
Fix generating dashboard poster on production
Browse files Browse the repository at this point in the history
In commit 905ac48 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.
  • Loading branch information
javierm committed Jan 11, 2022
1 parent 23a9ee6 commit a6fec0b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/dashboard_poster.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import "font-awesome/variables";
@import "font-awesome/mixins";
@import "font-awesome/core";
@import "foundation_and_overrides";
@import "mixins/*";
@import "dashboard";
2 changes: 1 addition & 1 deletion app/views/dashboard/poster/index.pdf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%= wicked_pdf_stylesheet_link_tag "application" -%>
<%= wicked_pdf_stylesheet_link_tag "dashboard_poster" -%>
<%= wicked_pdf_stylesheet_link_tag "pdf_fonts" -%>
</head>
<body class="dashboard-poster-pdf">
Expand Down
1 change: 1 addition & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Rails.application.config.assets.precompile += %w[stat_graphs.js]
Rails.application.config.assets.precompile += %w[dashboard_graphs.js]
Rails.application.config.assets.precompile += %w[application-rtl.css]
Rails.application.config.assets.precompile += %w[dashboard_poster.css]
Rails.application.config.assets.precompile += %w[print.css]
Rails.application.config.assets.precompile += %w[pdf_fonts.css]
Rails.application.config.assets.precompile += %w[sdg/*.png]
Expand Down

0 comments on commit a6fec0b

Please sign in to comment.