Rails代码库之外的哪些东西会影响资产预编译?
我的同事遇到了资产预编译问题,但对我来说效果很好。我们正在运行相同的代码。我们在版本控制中有 Gemfile 和 Gemfile.lock,所以它们是相同的,并且 application.rb 对我们双方来说都是相同的(例如,config.assets.enabled = true
为我们双方设置了。)
这是两个相关文件。我们遇到的问题如下。
应用程序/视图/布局/application.html.erb:
...
<%= stylesheet_link_tag "application", :media => "all" %>
...
应用程序/资产/样式表/application.css:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require booking_availability_table
*= require bootstrap_and_overrides
*= require browse_coaches
*= require landing_pages
*= require layout
*= require lightbox
*/
注意:这些文件有些是 .css,有些是 .css.less,有些是 .css.scss。
问题:
加载主页时,他收到错误
TypeError in Static_pages#home
can't convert nil into String
(in /path/to/app/assets/stylesheets/layout.css.scss)
Extracted source (around line #20)
20: <%= stylesheet_link_tag "application", :media => "all" %>
从实验性删除中,我们看到只有.css.scss文件导致了问题。删除application.css
与 SASS 文件对应的行会阻止错误发生并让页面加载。但是,如果我们这样做:
然后主页有大量指向 的链接/stylesheets/___.css
,这会导致 404,而不是/assets/____.css
像我那样正确。
我们尝试了什么:
我尝试使用调试器在我们的两台机器上逐步加载主页。我们的代码执行在这里发散:
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/sprockets/helpers/rails_helper.rb:
def stylesheet_link_tag(*sources)
...
sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'css')
asset.to_a.map { |dep|
super(dep.pathname.to_s, { :href => path_to_asset(dep, :ext => 'css', :body => true, :protocol => :request, :digest => digest) }.merge!(options))
}
else
super(source.to_s, { :href => path_to_asset(source, :ext => 'css', :body => body, :protocol => :request, :digest => digest) }.merge!(options))
end
end.join("\n").html_safe
具体来说,该声明asset_paths.asset_for(source, 'css')
对我的同事提出了错误,但对我没有。
我们还尝试卸载并重新安装 rails 和 rvm。