Skip to content

Conversation

@hahmed
Copy link
Contributor

@hahmed hahmed commented Jul 5, 2021

Summary

When creating a new app and running the rails application (rails welcome page), there is an error with the /favicon.ico request. This PR adds an internal route for the rails template to serve the favicon by sending back an head :ok response.

Previously the error we got:

Started GET "/favicon.ico" for 127.0.0.1 at 2017-06-21 10:10:01 +0100

ActionController::RoutingError (No route matches [GET] "/favicon.ico"):

I have moved the favicon into a header element -- one less route to override.

Other Information

Fixes #29578

To replicate the error, create a new rails app, on chrome run rails s then hard refresh should make a request for the favicon.

Screenshot:

Screenshot 2021-07-24 at 21 21 07

@rails-bot rails-bot bot added the railties label Jul 5, 2021
@hahmed hahmed marked this pull request as ready for review July 5, 2021 21:29
@p8
Copy link
Member

p8 commented Jul 6, 2021

The root route to the welcomes_controller gets overridden in apps.
Does this also work as expected for the 'favicon.ico'?
Will it be confusing for new users why the favicon.ico returns a 204 by default?

@p8
Copy link
Member

p8 commented Jul 6, 2021

An older but closed PR that tried adding the favicon to /public #29585

@p8
Copy link
Member

p8 commented Jul 7, 2021

We could also just inline the icon in the welcome template.

<link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%3E%3Ctext%20x='0'%20y='14'%20style='filter:%20invert(100%);'%3E🦄%3C/text%3E%3C/svg%3E" type="image/svg+xml" />

https://stackoverflow.com/a/62438464

This makes sure there are no extra routes, which might still be enabled by default.
And adding your own favicon.ico in /public would still work.

@hahmed hahmed force-pushed the add-favicon-to-internal-routes branch 3 times, most recently from 5a86de7 to 5d1146f Compare July 8, 2021 20:52
@hahmed
Copy link
Contributor Author

hahmed commented Jul 8, 2021

We could also just inline the icon in the welcome template.

@p8 inlining the favicon works for me 🙂

@zzak
Copy link
Member

zzak commented Jul 9, 2021

@hahmed Curious where you got the svg from, does it show up in the screenshot in the description of this PR too?

LGTM though, I generally like this approach but we may want to move the SVG content to a helper that can be tested, this way if Rails ever changes its logo a code search for "logo" will show up. 🤔

@sunny
Copy link
Contributor

sunny commented Jul 11, 2021

Curious where you got the svg from

It’s actually a jpg. Which is not ideal since it has no transparency:

image

An SVG would be great here. Using this SVG it would look more like this:

image

we may want to move the SVG content to a helper that can be tested, this way if Rails ever changes its logo a code search for "logo" will show up.

If we do that for the favicon it would mean doing this for all other images on the page (which also include the logo). Perhaps a comment, e.g. <!-- Rails logo --> would be enough, here?

@hahmed hahmed force-pushed the add-favicon-to-internal-routes branch 2 times, most recently from e67d102 to 1cdd4cf Compare July 12, 2021 20:56
@hahmed
Copy link
Contributor Author

hahmed commented Jul 12, 2021

LGTM though, I generally like this approach but we may want to move the SVG content to a helper that can be tested, this way if Rails ever changes its logo a code search for "logo" will show up. 🤔

I have moved this to a var in the view, added a descriptive name, hope that's ok?

Could you clarify how it could be tested? Also I'm not sure we are testing the other 2 images on the page either...

@hahmed hahmed force-pushed the add-favicon-to-internal-routes branch from 1cdd4cf to f72953a Compare July 12, 2021 21:10
@hahmed hahmed force-pushed the add-favicon-to-internal-routes branch from 4737415 to 4def5dd Compare July 12, 2021 21:42
@hahmed hahmed force-pushed the add-favicon-to-internal-routes branch from 922842a to 98824f6 Compare July 13, 2021 19:57
@p8 p8 added ready PRs ready to merge and removed ready PRs ready to merge labels Jul 17, 2021
@p8
Copy link
Member

p8 commented Jul 17, 2021

The logo is a bit outdated. I'll try to see if I can generate a SVG from https://www.pngegg.com/en/png-zrbae

@p8
Copy link
Member

p8 commented Jul 18, 2021

I've created an SVG that looks like this:
image

<?xml version="1.0" encoding="UTF-8"?>
<svg width="320px" height="320px" viewBox="0 0 320 320" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <title>Icon</title>
    <g id="Icon" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="Ruby-On-Rails-Logo" transform="translate(5.000000, 20.000000)" fill="#D81E00">
            <path d="M21.9330706,285 L168.175426,285 C147.940858,150.691706 196.882383,66.3142902 315,31.8677536 C315,21.7851284 315,31.8677536 315,21.7851284 C161.25283,24.9116278 63.5638533,112.649918 21.9330706,285 Z" id="Path"></path>
            <polygon id="Path" points="40.4082643 185.91571 12.7326494 174.401663 -1.42108547e-14 205.44271 29.5711966 216.647115"></polygon>
            <polygon id="Path" points="180.473102 268.073643 204.936016 276.410966 204.936016 254.508673 180.489644 244.338107"></polygon>
            <polygon id="Path" points="100.589519 97.2287606 76.6840156 79.1687021 55.2440791 100.183105 81.5143239 117.433725"></polygon>
            <polygon id="Path" points="184.575679 184.896295 207.95203 200.24661 211.727729 181.205266 189.863653 164.68746"></polygon>
            <polygon id="Path" points="261.73401 65.8959446 269.354234 82.32954 285.318256 72.7048596 278.310129 56.9829895"></polygon>
            <polygon id="Path" points="261.9137 16.1845473 255.598479 7.10542736e-15 232.79602 3.48896323 240.463873 20.0252725"></polygon>
            <polygon id="Path" points="211.934119 111.580675 226.722547 127.792601 238.023925 113.903715 223.468375 96.5468685"></polygon>
            <polygon id="Path" points="179.686858 38.4952218 164.641931 20.0252725 139.84762 32.5552992 156.601324 50.9216753"></polygon>
        </g>
    </g>
</svg>

Co-authored-by: Sunny Ripert <sunny@sunfox.org>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
@hahmed hahmed force-pushed the add-favicon-to-internal-routes branch from 98824f6 to 49332c9 Compare July 24, 2021 20:27
@hahmed
Copy link
Contributor Author

hahmed commented Jul 24, 2021

Awesome, thanks @p8 I have updated and added a screenshot of the new svg logo. Does that look ok now?

@p8
Copy link
Member

p8 commented Jul 24, 2021

Thanks @hahmed and @sunny! This looks PR great to me.

@p8 p8 added the ready PRs ready to merge label Jul 24, 2021
@byroot byroot merged commit 5ac9366 into rails:main Jul 28, 2021
@hahmed hahmed deleted the add-favicon-to-internal-routes branch July 28, 2021 19:30
@WaKeMaTTa
Copy link

Why I never though about it? Good job ma'men!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

railties ready PRs ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No route matches [GET] "/favicon.ico"

6 participants