Rails 3.1 absolute URL to an image
put this in application_helper.rb
def asset_url asset "#{request.protocol}#{request.host_with_port}#{asset_path(asset)}"end
then you can use asset_url
in your views.
See the Using asset hosts section in the documentation. You need to specify an asset_host
. You can also construct it dynamically from the request chaining "#{request.protocol}#{request.host_with_port}"
For Rails 4, and maybe earlier, use:
config.action_mailer.asset_host = 'https://assets.com'