Reputation: 386
In a Rails 4 app, I have a static file stored in the /public
directory. And I have a view partial that links to that file like this:
<%= "Please download the #{link_to 'Static file', '/static_filename.docx'}".html_safe %>
The partial is used in both a regular view and in a mailer view. In the regular view, this works perfectly, and the link url is like this:
www.example.com/static_filename.docx
But in the mailer, the url comes out like this, missing the host name:
/static_filename.docx
This, despite the fact that I took care to configure the default url in config/environments/production.rb
as such:
config.action_mailer.default_url_options = { :host => 'http://www.example.com' }
I'm puzzled as to what I am doing wrong, and why the regular view works when the mailer does not work.
Any help would be greatly appreciated!
Upvotes: 0
Views: 1033
Reputation: 56
You should your asset host for action mailer
config.action_mailer.asset_host = "http://www.yourdomain.com"
Secondly, use the asset_path() wrapper on your asset, ie
<%= "Please download the #{link_to 'Static file', asset_path('/static_filename.docx')}".html_safe %>
Upvotes: 2