0

When I send links in an email from a Ruby on Rails application, I use the link_to function:

<%= link_to @user.name, controller: 'users', action: 'show', id: @user.id, only_path: false %>

This will produce a link like this:

http://www.example.com/users/58

Or if I'm on my development environment:

http://localhost:3000/users/58

How do I do the same with images? I've tried:

<%= image_tag "/invitations/#{@invitation.id}/open.png", only_path: false %>

I was hoping to see:

<img alt="Open" src="http://www.example.com/invitations/43/open.png" />

But I got this instead unfortunately:

<img alt="Open" only_path="false" src="/invitations/43/open.png" />

How do I get img tags to use the full URL based on the host I specified in my environment files?

at.
  • 50,922
  • 104
  • 292
  • 461
  • Have you checked the accepted answer of this question? http://stackoverflow.com/questions/15490327/how-do-i-get-full-url-to-an-image-in-a-rails-asynchronous-mailer?rq=1 it is mentioned a weird behavior of AssetUrlHelper, perhaps you Rails version is affected – Benjamin Bouchet Oct 05 '14 at 11:55
  • This is not an asset – at. Oct 05 '14 at 18:02

1 Answers1

0

You should try to add this config to your development.rb file

config.action_mailer.asset_host = "http://localhost:3000"
Mkou
  • 525
  • 4
  • 12