[openstreetmap/openstreetmap-website] Facelift `offline.html` and use Bootstrap classes for "notifications" under the search bar (PR #3907)
Andy Allan
notifications at github.com
Wed Feb 8 15:26:11 UTC 2023
@gravitystorm commented on this pull request.
> @@ -1,7 +1,9 @@
+<div class="alert alert-danger text-center">
> Would this work
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 `<p>` tags and no `<%=` outputs. This works:
```
<% if Settings.status == "database_offline" %>
<% flash.now[:warning] = t("layouts.osm_offline") %>
<% else %>
<% flash.now[:warning] = t("layouts.osm_read_only") %>
<% end %>
```
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 `flash.now` in any views. When I said:
> for example by using `flash.now[:warning] = t("layouts.osm_offline")` **in the controller**
... I was thinking about changing the `site#offline` method (in SiteController) something like this:
```diff
- def offline; end
+ def offline
+ flash.now[:warning] = if Settings.status == "database_offline"
+ t("layouts.osm_offline")
+ else
+ t("layouts.osm_read_only")
+ end
+ end
```
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. [I found some examples of how to do this](https://stackoverflow.com/a/45581659/105451), e.g.
```ruby
def offline
flash.now[...]
...
render :html => nil, :layout => true
end
```
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/3907#discussion_r1100295421
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/3907/review/1289416628 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20230208/6868c32f/attachment.htm>
More information about the rails-dev
mailing list