Search code examples
ruby-on-railsruby-on-rails-3asset-pipeline

How to have asset_path return an absolute URL?


How can you get asset_path to return an absolute URL?

I need the absolute URL for a meta tag like so:

<meta property="og:image" content="<%= asset_path('logo_400x200.jpg') %>" />

The problem with asset_path here is that it outputs a URL with "//site.com/logo_400x200.jpg" and the meta tag needs an absolute path.

Any ideas on how to get an absolute path with the Rails asset_path?


Solution

  • Use asset_url

    <meta property="og:image" content="<%=asset_url('logo_400x200.jpg') %>" />