<p></p>
<p><b>@gravitystorm</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/3907#discussion_r1100295421">app/views/site/offline.html.erb</a>:</p>
<pre style='color:#555'>> @@ -1,7 +1,9 @@
+<div class="alert alert-danger text-center">
</pre>
<blockquote>
<p dir="auto">Would this work</p>
</blockquote>
<p dir="auto">Something similar to this actually does work - the trick is that you can add flash messages from a view (since it appears the view is processed before the layout) but you need to avoid also writing the message at the same time. So no <code class="notranslate"><p></code> tags and no <code class="notranslate"><%=</code> outputs. This works:</p>
<pre class="notranslate"><code class="notranslate"><% if Settings.status == "database_offline" %>
  <% flash.now[:warning] = t("layouts.osm_offline") %>
<% else %>
  <% flash.now[:warning] = t("layouts.osm_read_only") %>
<% end %>
</code></pre>
<p dir="auto">However, I find that a bit unintuitive, since it depends on a timing issue with rendering views vs layouts, and usually flash messages are set in the controller before rendering starts. So I would avoid using <code class="notranslate">flash.now</code> in any views. When I said:</p>
<blockquote>
<p dir="auto">for example by using <code class="notranslate">flash.now[:warning] = t("layouts.osm_offline")</code> <strong>in the controller</strong></p>
</blockquote>
<p dir="auto">... I was thinking about changing the <code class="notranslate">site#offline</code> method (in SiteController) something like this:</p>
<div class="highlight highlight-source-diff" dir="auto"><pre class="notranslate"><span class="pl-md"><span class="pl-md">-</span>  def offline; end</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>  def offline</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>    flash.now[:warning] = if Settings.status == "database_offline"</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>                            t("layouts.osm_offline")</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>                          else</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>                            t("layouts.osm_read_only")</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>                          end</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>  end</span></pre></div>
<p dir="auto">At this point, the view can be empty, and this will work. Having an empty view is a bit strange, so I would either think of something to put in there (for example, further explanation, but I'm not sure if that is useful) or else remove the view entirely and be explicit in the controller that there's nothing else to render. <a href="https://stackoverflow.com/a/45581659/105451" rel="nofollow">I found some examples of how to do this</a>, e.g.</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">offline</span>
  <span class="pl-en">flash</span><span class="pl-kos">.</span><span class="pl-en">now</span><span class="pl-kos">[</span>...<span class="pl-kos">]</span>
  ...
  <span class="pl-en">render</span> <span class="pl-pds">:html</span> <span class="pl-c1">=></span> <span class="pl-c1">nil</span><span class="pl-kos">,</span> <span class="pl-pds">:layout</span> <span class="pl-c1">=></span> <span class="pl-c1">true</span>
<span class="pl-k">end</span></pre></div>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/3907#discussion_r1100295421">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLPEWKZ4LO6DDF4KYGLWWO3JHANCNFSM6AAAAAAUC5ITLA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLMBV2S2JJPY6FTATVTWWO3JHA5CNFSM6AAAAAAUC5ITLCWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTSM3LX3I.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/3907/review/1289416628</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/3907#discussion_r1100295421",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/3907#discussion_r1100295421",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>