Rails和SLIM html image_tag指向图像而不是资产

时间:2018-10-24 07:01:13

标签: ruby-on-rails ruby-on-rails-4 slim-lang

我有一种情况,我需要使用用SLIM编写的模板发送电子邮件。我用以下我认为有必要的environment/development.rb修复了config(同样基于我的研究)

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

我知道在此步骤中它正确指向了我的根URL。然后在我的mailer.html.slim中,我会看到以下内容:

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

我已经尝试了以下方法:

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

什么都没有做,但好事了,它现在显示Alt知道它仍然在按其路径工作。

当前= image_tag的计算结果为:

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

您知道为什么应用程序找不到正常的管道路径吗? 我需要images/images/logo-old.png

来代替assets/images/logo-old.png

编辑:

因此,为了进行结果比较,如果我进行image_url "logo-old.png",则路径结果为/assets/logo-old.png

如果我做image_url "images/logo-old.png",路径将到达images/images/logo-old.png

我的图片在app/assets/images/logo-old.png

1 个答案:

答案 0 :(得分:0)

1)http://localhost:3000/images/images/logo-old.png是您的app/assets/images/images/logo-old.png的正确文件夹结构吗?

2)您是否将app/assets/images添加到资产管道?

How to add folders to asset pipeline

Javascript does not work from a bootstrap template in rails

3)您是否使用Rails.application.config.assets.paths检查了rails console中的默认搜索路径,是否尝试正确组织要存储在app/assets/images文件夹中的图像并将该文件夹添加到资产管道?

那么您应该可以进行image_url "logo-old.png"

谢谢!