【问题标题】:is url active storage with rails_blob_path valid to use in meta tags带有 rails_blob_path 的 url 活动存储在元标记中是否有效
【发布时间】:2020-05-20 01:01:59
【问题描述】:

我的模型用户有一个avatar,我为og:image 设置了元标记rails_blob_path,我在控制器中设置了这个,它的 URL 的结果喜欢:

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

这是在development 模式下,如果它在production 下,该URL 是否有效设置为元标记 og:image

【问题讨论】:

    标签: html ruby-on-rails ruby meta-tags rails-activestorage


    【解决方案1】:

    在这种情况下,您需要一个完整的 URL。特别是我使用了方便的url_for方法,如下:

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

    另外,我发现某些应用程序要正确解析您的图像(例如 Whatsapp),最好排除该方案(httpshttp),从而得到一个元标记,如:

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

    希望有帮助!

    【讨论】:

    • 你在生产中使用了 thi 吗?我试过这个和 twitter:image 没有炫耀
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    相关资源
    最近更新 更多