0

I have a scenario where I need to send emails using a template written in SLIM. I fixed my environment/development.rb with the following config that I find necessary (also based from my research)

config.assets.precompile += %w( print.css )
config.serve_static_assets = true (still using Rails 4.1.16)
config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
config.action_controller.asset_host = 'http://localhost:3000'
config.action_mailer.asset_host = config.action_controller.asset_host

I know it's pointing correctly to my root url on this step. Then In my mailer.html.slim I have something like this:

div align="left" style="border-collapse: collapse; padding-left: 30px;padding-top: 30px;padding-bottom: 30px;float:left;"
  a href="http://#{App.url}"
      = image_tag "images/logo-old.png", style: "display:inline-block", border: "0", alt: App.name, width: 139, height: 44, title: App.name

I tried the following already:

= image_tag "logo-old.png"
= image_tag "assets/images/logo-old.png"
= image_url "logo-old.png"

Nothing's working but good thing its now showing the Alt to know its still working by its path.

The current = image_tag evaluates to :

 src="https://ci5.googleusercontent.com/proxy/83z0D3PVOqx-FwFFMwztfYBs5CSWHiURyxSUP6cZ3dq7Zo47k9mNPgotrijVmmWGxPHqblRTGCePqN4RrfEhHh_665
MdAQ=s0-d-e1-ft#http://localhost:3000/images/images/logo-old.png"

Any idea why the app can't find the normal pipeline path? Instead of images/images/logo-old.png I need the assets/images/logo-old.png

Edit:

So for result comparison, if I do image_url "logo-old.png" the path results to /assets/logo-old.png

If I do image_url "images/logo-old.png" the path results to images/images/logo-old.png

My image is in app/assets/images/logo-old.png

Theresa
  • 35
  • 2
  • 13

1 Answers1

0

1) is http://localhost:3000/images/images/logo-old.png the correct folder structure of your app/assets/images/images/logo-old.png ?

2) did you add the app/assets/images to the asset pipeline?

How to add folders to asset pipeline

Javascript does not work from a bootstrap template in rails

3) did you check with Rails.application.config.assets.paths the default search paths in your rails console, did you try to organize correctly the images to be stored inside app/assets/images folder and added that folder to the asset pipeline?

then you should be able to do image_url "logo-old.png"

Thanks!

Fabrizio Bertoglio
  • 5,890
  • 4
  • 16
  • 57
  • Hi! Thanks for breaking down what I should double check. Rechecked on my `Rails.application.config.assets.path` and it does contain what I need from my project : `"/home/spotontheresa/Documents/projects/myproject/app/assets/images"` My project is also structured correctly as far as I know it's app - assets - images - the image I need /logo-old.png – Theresa Oct 24 '18 at 23:52
  • Any more ideas where I should check? – Theresa Oct 24 '18 at 23:52
  • @Theresa it should be using the pre-compiled asset from `public/assets` including the fingerprint, while it is falling back to the asset in your `app/assets/images` folder. This fallback behavior can be disabled https://guides.rubyonrails.org/asset_pipeline.html#raise-an-error-when-an-asset-is-not-found inside `development.rb`. The fact is you need to clear all your precompiled assets and precompile sometimes to see you changes take effect – Fabrizio Bertoglio Oct 25 '18 at 06:57