images in emails using roadie gem

瘦欲@ 提交于 2020-01-24 16:56:22

问题


I want to know how to show images in email by using roadie gem. Using roadie i'm able to inline my stylesheets but it's not showing images. I have tried both

<%= image_tag "pic.jpg" %>

and

<img src="pic.jpg"/> or <img src="assets/images/pic.jpg"/>

inside my mail template, but it's not showing any of the images. Any help?


回答1:


It's been a long time since I asked this question and I was pretty new to rails development so didn't really know what I was doing wrong. Anyways so the issue is when we use image_tag helper or asset_path helpers for rendering images, it makes relative paths for that image(you can check it in firebug or some other tool) and they won't work inside emails or lets say on any other remote server (other than where the app is hosted)

Fix:

You can specify where your assets are hosted by:

config.action_controller.asset_host = 'http://your_server.com'



回答2:


Quite old, but if somebody needs this...

Usually I use:

%img{:src => asset_url('/email/logo.png') }

also, as mentioned in the comments, be sure to have config.action_mailer.asset_host configured

example: config.action_mailer.asset_host = "http://localhost:3000/assets/"



来源:https://stackoverflow.com/questions/19609089/images-in-emails-using-roadie-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!