Ruby On Rails: ActionMailer : Get full URL to an image in a Rails asynchronous mailer

Well this is odd behavior, but I’ve resolved this issue. It turns out that unless the action_mailer.asset_host starts with http:// then it will be ignored. There is a Regex in actionpack/lib/action_view/helpers/asset_url_helper.rb that defines a valid ActionMailer URI:

URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}

However, if you put a http:// in front of the action_controller.asset_host then you will end up with links to http://
So to resolve it I had to add the following to my development.rb

 config.action_controller.asset_host = ''
 config.action_mailer.asset_host = ''

Just to be clear, this is Rails 4.0.0beta1 with the emails being sent asynchronously with Sidekiq, I am not sure if this affects Rails 3.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s