简体   繁体   English

资产管道中的(轨道)资产显示在index.html.erb文件中,但不显示在show.html.erb中

[英](Rails) asset from asset pipeline shows up in index.html.erb file, but not show.html.erb

I am trying to get both an image and a CSS style from my asset pipeline ni rails 4. I have an index.html.erb and a show.html.erb. 我正在尝试从资产管道ni rails 4中获取图像和CSS样式。我有一个index.html.erb和show.html.erb。 I have the exact same code in each, but it works in the index.html file, but not in the show.html file. 我每个人都有完全相同的代码,但它在index.html文件中有效,但在show.html文件中无效。

Code: 码:

 <!-- Styles -->
<link rel="stylesheet" href="assets/styles-bluegreen.css" id="theme-styles">

 <a href="index.html" id="logo">
     <img src="assets/my-logo.png" alt="My Blog">
 </a>

I have this exact same code, because I copied and pasted (yes, I know it's against rails dry policy). 我有完全相同的代码,因为我复制并粘贴了(是的,我知道这违反了rails dry政策)。 I originally had this in a _header.html.erb partial, and the code did not work in the partial either, so i put the exact code in each file, and it works in the index.thml.erb, but no in the show.html.erb. 我最初是在_header.html.erb部分中使用此代码的,而该代码也不能在该部分中使用,因此我将确切的代码放在每个文件中,并且它在index.thml.erb中有效,但在显示中没有.html.erb。 What could be the reason? 可能是什么原因?

Note, I have also tried: 注意,我也尝试过:

<link rel="stylesheet" href="stylesheets/styles-bluegreen.css" id="theme-styles">

and

<link rel="stylesheet" href="assets/stylesheets/styles-bluegreen.css" id="theme-styles">

Here is my asset pipeline: 这是我的资产管道:

资产管道

If you copy-paste the snippet, there's no reason for them to behave differently except one of your view (index or show) is cached and it is served to the client directly instead of being rendered. 如果您复制粘贴该片段,则没有理由让它们表现不同,只是缓存了您的视图(索引或显示)之一,并将其​​直接提供给客户端而不是呈现。 Can you check if this is the case? 您能检查这种情况吗?

Btw, you really should use stylesheet_link_tag because links to assets might differ from development to production environments. 顺便说一句,您确实应该使用stylesheet_link_tag因为到development环境和production环境的资产链接可能会有所不同。 This helper renders those links correspondingly to environments. 该帮助器将这些链接相应地呈现到环境。

isn't it href="<%= asset_path('styles-bluegreen.css')%>" 不是href="<%= asset_path('styles-bluegreen.css')%>"

And then for the picture src="<%= asset_path('my-logo.png')%>" 然后对于图片src="<%= asset_path('my-logo.png')%>"

Also, you'd have to add .erb to the end of the show.html filename (so show.html.erb) 另外,您还必须在show.html文件名的末尾添加.erb(因此show.html.erb)

That usually works for me. 通常对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM