I have searched around and can't rectify the situation based on the responses to other similar questions. I seem to have broken the asset pipeline somehow but can't seem to figure out how.
我已经找遍了,无法根据其他类似问题的回答来纠正这种情况。我似乎以某种方式破坏了资产管道,但似乎不知道该怎么做。
None of my assets are being loaded at all; rails seems to just be ignoring my manifest files. When I inspect my page in firebug, only the 'non-compiled' text inside my manifest files (both js and css) is being displayed - almost as if the asset pipeline wasn't even enabled.
我的所有资产都没有被载入;rails似乎忽略了我的manifest文件。当我在firebug中检查我的页面时,在我的清单文件(包括js和css)中,只有“非编译”的文本被显示出来——几乎就好像资产管道还没有启用一样。
I deleted the contents of public/assets since I was adding a new file to the manifest which seemed to start this behavior.
我删除了公共/资产的内容,因为我在清单中添加了一个新的文件,这似乎启动了这种行为。
Current configuration:
当前配置:
environments/development.rb
环境/ development.rb
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
application.rb
application.rb
# Enable the asset pipeline
config.assets.enabled = true
config.assets.manifest = config.root
# Add extra assets for precompiling
config.assets.precompile += ['admin.js', 'admin.css']
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
4 个解决方案
#1
3
The issue was caused by using an incompatible version of ruby. I was using version 2.1.2 which lead to unusual behavior from the sprockets gem (which powers the asset pipeline). This was fixed by downgrading to ruby 1.9.3. I haven't done any experimentation for fear of breaking it again but maybe this has been addressed in later versions of sprockets. I am using sprockets 2.1.3.
这个问题是由使用不兼容的ruby版本引起的。我使用的是2.1.2版本,它导致了来自spro佝偻病gem(支持资产管道)的异常行为。这是通过降级到ruby 1.9.3来解决的。我还没有做过任何实验,因为害怕再次破坏它,但这可能已经在以后版本的spro佝偻病中得到了解决。我使用的是spro佝偻病2.1.3。
See: Rails 3.2.8 Application.js and Application.css are not working as expcted
看:Rails 3.2.8应用程序。js和应用。css不像扩展的那样工作
#2
3
I had the same issue. You can still use Ruby 2.1.2, just upgrade rails to latest 3.2.x version - it's 3.2.22
我也有同样的问题。您仍然可以使用Ruby 2.1.2,只需将rails升级到最新的3.2即可。x版本-是3。2。22
Gemfile:
Gemfile:
gem 'rails', '3.2.22'
And run:
并运行:
$ bundle update rails
#3
1
Always remember two things when you want to handle Rails asset pipleline:-
当您想要处理Rails资产管道时,请始终记住两件事:-
- if you want all you newly created js/css to autoinclude in
application.js/css
,pls add them in... ELSE - 如果您想要在应用程序中自动包含所有新创建的js/css。js / css,请将它们添加在…其他的
-
IF you dont wont to add in
manifest
file(application.js/css
) then useprecompile directive
in yuur environment file.如果您不习惯添加manifest文件(application.js/css),那么在yuur环境文件中使用预编译指令。
config.assets.precompile=%w(custom.css,custom2.js...etc)
config.assets.precompile = % w(custom.css custom2.js…等)
so make sure you have either of these...
所以要确保你有这些…
===========for example=-=============
= = = = = = = = = = =例如= - = = = = = = = = = = = = =
suppose you have new css/js
file:- custom.css
inside
假设您有新的css/js文件:- custom。css内
app/assets/stylesheets/
so you can include in
所以你可以加入
application.css
// = require 'custom'
OR
或
use precompile directive:-
使用预编译指令:-
config.assets.precompile += %w( custom.css )
and then reference it like you always do
然后像往常一样引用它
stylesheet_link_tag "custom"
same applies for js also
js也一样。
#4
0
I just spent a few hours troubleshooting this issue (in 2017!) and it turned out I just needed to remove the gem active_reload
. Updating rails and ruby was having no effect for me. The thread where I found that gold is here: https://github.com/rails/rails/issues/2715
我刚刚花了几个小时来解决这个问题(2017年!),结果我只需要删除gem active_reload。更新rails和ruby对我没有任何影响。我发现黄金在这里的线程:https://github.com/rails/rails/es/2715。
#1
3
The issue was caused by using an incompatible version of ruby. I was using version 2.1.2 which lead to unusual behavior from the sprockets gem (which powers the asset pipeline). This was fixed by downgrading to ruby 1.9.3. I haven't done any experimentation for fear of breaking it again but maybe this has been addressed in later versions of sprockets. I am using sprockets 2.1.3.
这个问题是由使用不兼容的ruby版本引起的。我使用的是2.1.2版本,它导致了来自spro佝偻病gem(支持资产管道)的异常行为。这是通过降级到ruby 1.9.3来解决的。我还没有做过任何实验,因为害怕再次破坏它,但这可能已经在以后版本的spro佝偻病中得到了解决。我使用的是spro佝偻病2.1.3。
See: Rails 3.2.8 Application.js and Application.css are not working as expcted
看:Rails 3.2.8应用程序。js和应用。css不像扩展的那样工作
#2
3
I had the same issue. You can still use Ruby 2.1.2, just upgrade rails to latest 3.2.x version - it's 3.2.22
我也有同样的问题。您仍然可以使用Ruby 2.1.2,只需将rails升级到最新的3.2即可。x版本-是3。2。22
Gemfile:
Gemfile:
gem 'rails', '3.2.22'
And run:
并运行:
$ bundle update rails
#3
1
Always remember two things when you want to handle Rails asset pipleline:-
当您想要处理Rails资产管道时,请始终记住两件事:-
- if you want all you newly created js/css to autoinclude in
application.js/css
,pls add them in... ELSE - 如果您想要在应用程序中自动包含所有新创建的js/css。js / css,请将它们添加在…其他的
-
IF you dont wont to add in
manifest
file(application.js/css
) then useprecompile directive
in yuur environment file.如果您不习惯添加manifest文件(application.js/css),那么在yuur环境文件中使用预编译指令。
config.assets.precompile=%w(custom.css,custom2.js...etc)
config.assets.precompile = % w(custom.css custom2.js…等)
so make sure you have either of these...
所以要确保你有这些…
===========for example=-=============
= = = = = = = = = = =例如= - = = = = = = = = = = = = =
suppose you have new css/js
file:- custom.css
inside
假设您有新的css/js文件:- custom。css内
app/assets/stylesheets/
so you can include in
所以你可以加入
application.css
// = require 'custom'
OR
或
use precompile directive:-
使用预编译指令:-
config.assets.precompile += %w( custom.css )
and then reference it like you always do
然后像往常一样引用它
stylesheet_link_tag "custom"
same applies for js also
js也一样。
#4
0
I just spent a few hours troubleshooting this issue (in 2017!) and it turned out I just needed to remove the gem active_reload
. Updating rails and ruby was having no effect for me. The thread where I found that gold is here: https://github.com/rails/rails/issues/2715
我刚刚花了几个小时来解决这个问题(2017年!),结果我只需要删除gem active_reload。更新rails和ruby对我没有任何影响。我发现黄金在这里的线程:https://github.com/rails/rails/es/2715。