Files
nairobi/app/views/dashboard/poster/index.pdf.erb
Javi Martín c5103d3025 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.
2022-01-12 13:45:59 +01:00

43 lines
1.6 KiB
Plaintext

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%= wicked_pdf_stylesheet_link_tag "dashboard_poster" -%>
<%= wicked_pdf_stylesheet_link_tag "pdf_fonts" -%>
</head>
<body class="dashboard-poster-pdf">
<div class="poster-header">
<h1>
<strong><%= t("dashboard.poster.index.poster_title") %>
<br>
<%= wicked_pdf_image_tag("finger.png") %>
<%= t("dashboard.poster.index.poster_subtitle") %>
</strong>
</h1>
<p class="intro">
<%= sanitize(t("dashboard.poster.index.intro_text", org: Setting["org_name"])) %>
</p>
<p class="text-center proposal-code">
<strong><%= t("dashboard.poster.index.proposal_code", code: proposal.code) %></strong>
</p>
<div class="proposal-image">
<% if proposal.image.present? %>
<div class="overflow-image" style="background-image: url(<%= asset_url proposal.image.attachment.url(:large) %>);"></div>
<% else %>
<div class="overflow-image" style="background-image:url('<%= "file://#{Rails.root.join("app","assets","images","default_mailing.jpg")}" %>');"></div>
<% end %>
</div>
<div class="poster-content">
<h2 class="text-center"><strong><%= t("dashboard.poster.index.support") %></strong></h2>
<%= wicked_pdf_image_tag "quote_before_blue.png" %>
<h3><strong><%= proposal.title %></strong></h3>
<%= wicked_pdf_image_tag "quote_after_blue.png" %>
<p class="poster-footer">
<%= sanitize(t("dashboard.poster.index.footer", link: proposal_url(proposal))) %>
</p>
</div>
</div>
</body>
</html>