Search code examples
htmlruby-on-railsrubymeta-tagsrails-activestorage

is url active storage with rails_blob_path valid to use in meta tags


I have Model User that has one avatar, and I set meta tag for og:image with rails_blob_path, I set this in the controller and the result of URL of it likes:

myappname/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZpud9--aa382324e6d9968973/thepic-here-3783384.jpg?disposition=attachment

this is if in development mode, if it is in production would it be valid for that URL to set into meta tags og:image ?


Solution

  • You need a full URL, in that case. Particularly, I use the handy url_for method, as follows:

    url_for(asset.variant(
                    resize_to_limit: [max_width, max_height]
                  ))
    

    Also, I've found that for certain apps to correctly parse your image (Whatsapp for instance), it's better to exclude the scheme (https or http), thus getting a metatag like:

    <meta property="og:image" itemprop="image" content="//yourcoolsite.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbDhFIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--0507940c0531918f2c8a85ec0eba799b5a291789/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2/logo.jpg">
    

    Hope that helps!