简体   繁体   English

Rails资产管道-CSS未更新

[英]Rails Asset Pipeline - CSS Not Updating

I am trying to update the font in a rails app - specifically the text in a brand class in the top navbar. 我正在尝试更新Rails应用程序中的字体-特别是顶部导航栏中品牌类中的文本。 I was successful in changing the font using google web fonts already, but now when I try to update the font again, it seems to be "stuck" on the last font I used. 我已经成功使用Google网络字体更改了字体,但是现在当我尝试再次更新字体时,它似乎卡在了我使用的最后一种字体上。 I precompiled assets before deploying to heroku, which is what I think may be causing the problem. 在部署到heroku之前,我已经对资产进行了预编译,这可能是导致问题的原因。 Now the changes are not updating locally or in production. 现在,更改不会在本地或生产中更新。

I have done a few things to troubleshoot but none seem to be working: 我已经做了几件事来进行故障排除,但是似乎都没有用:

  1. Restarted the rails server 重新启动Rails服务器
  2. Emptied the cache folder in the tmp folder 清空了tmp文件夹中的缓存文件夹
  3. Deleted public assets 删除公共资产
  4. Tried precompiling assets again - the font change does not work locally or on heroku 再次尝试预编译资产-字体更改在本地或在Heroku上不起作用
  5. Tried targeting a more specific css selector (.navbar .brand versus .brand - it worked earlier for .brand so don't think that is the issue) 尝试针对更具体的css选择器(.navbar .brand与.brand-它在.brand上更早起作用,所以不要认为这是问题所在)
  6. Cleared browsing history 清除浏览历史记录

Any ideas on what may be causing this? 关于什么可能导致此的任何想法?

Are you using turbolinks? 您在使用turbolinks吗? If so, read this 如果是这样,请阅读

Asset change detection 资产变更检测

You can track certain assets, like application.js and application.css, that you want to ensure are always of the latest version inside a Turbolinks session. 您可以跟踪某些资产,例如application.js和application.css,以确保它们始终是Turbolinks会话中的最新版本。 This is done by marking those asset links with data-turbolinks-track, like so: 这是通过用data-turbolinks-track标记这些资产链接来完成的,如下所示:

 <link href="/assets/application-9bd64a86adb3cd9ab3b16e9dca67a33a.css" 

rel="stylesheet" type="text/css" data-turbolinks-track> rel =“ stylesheet” type =“ text / css” data-turbolinks-track>

If those assets change URLs (embed an md5 stamp to ensure this), the page will do a full reload instead of going through Turbolinks. 如果这些资产更改了URL(嵌入md5标记以确保做到这一点),则该页面将进行完全重新加载,而不是通过Turbolinks。 This ensures that all Turbolinks sessions will always be running off your latest JavaScript and CSS. 这样可以确保所有Turbolinks会话将始终运行最新的JavaScript和CSS。

When this happens, you'll technically be requesting the same page twice. 发生这种情况时,从技术上讲,您将两次请求同一页面。 Once through Turbolinks to detect that the assets changed, and then again when we do a full redirect to that page. 一次通过Turbolinks检测到资产已更改,然后一次完全重定向到该页面。

Stupid mistake - had a navbar class styled in my css with font-style: monospace. 愚蠢的错误-我的CSS中有一个导航栏类,其字体样式为:等宽字体。 After clearing that, everything worked - hopefully the troubleshooting steps help others! 清除所有问题后,一切正常-希望故障排除步骤对其他人有所帮助!

  1. View your page source and search for the font src. 查看您的页面源代码并搜索src字体。 If you can't find it skip to 3. 如果找不到,请跳至3。

  2. Test the font and display code outside of the rails apps to make sure it is the asset pipeline. 在Rails应用程序外部测试字体并显示代码,以确保它是资产管道。

  3. If the src and display code work, provide your application.css and application.js to check your manifests. 如果src和display代码有效,请提供application.css和application.js来检查清单。

  4. What config files/code have you changed since your last assets:precompile that is not working properly. 自您上次Assets:precompile正常运行以来,您更改了哪些配置文件/代码。

My similar issue: Bootstrap, jQuery, and the Rails asset pipeline 我的类似问题: Bootstrap,jQuery和Rails资产管道

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

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