Css 更改未在 rails 应用中应用

Css changes are not being applied in rails app

我正在开发 rails 应用程序,但现在遇到了问题。

Early when I use to change my frontend styling and apply changes in css then they quickly show up on reload in brower.

But in present, don't know but something went wrong. Whenever I change css and save it then onload, things remain same. After debugging, I found that app is picking styling files from precompiled assets pipeline. So for the solution, I have to recompile the assets then 2 new files are generated against wach file changed. And there will be 4 files in total against a single css file in which changes are made. So now I have to delete old ones and then have to restart the serve and refreshing the browser will show all the changing and that is weird as I have to do it all the time for every single change. I can't figure as I am new to rails. Help....

如果您正在开发应用程序,则应删除 public/assets 目录。然后重新启动应用程序。不要运行asssts:precompile任务。您最近的资产更改将在不重新启动应用程序的情况下保持最新。

请先清除tmp缓存,然后运行服务器

$ rake tmp:cache:clear && rails server

所以我找到了原因,那是因为我有 运行 资产预编译的命令,我不应该 运行 因为 rails 已经这样做了对我来说可能是由于我的项目配置或者它的默认行为。

To solve this problem I have to delete my projects folder from my system and clone it again and things got normal again.

现在我再也不会运行资产预编译命令

我遇到了同样的问题并找到了解决方案:运行 rake assets:clobber,它将删除预编译的 css 和 js。然后 运行 yarn build --watch 重建 css 和 js 文件。

不要 运行 assets:build 因为同样的问题会恢复。