What sort of things OUTSIDE of the Rails codebase can affect asset precompilation?
My colleague is experiencing asset precompilation issues, while it works fine for me. We’re running the same code. We have Gemfile and Gemfile.lock in version control, so those are identical, and application.rb is the same for both of us (so, for example, config.assets.enabled = true is set for both of us.)
Here are the two relevant files. The issue we’re experiencing is below.
app/views/layouts/application.html.erb:
...
<%= stylesheet_link_tag "application", :media => "all" %>
...
app/assets/stylesheets/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
*/
note: Some of these files are .css, some are .css.less, and some are .css.scss.
The issue:
When loading the homepage, he gets the error
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" %>
From experimental deleting, we see that it’s only the .css.scss files that are causing the problem. Deleting the lines in application.css corresponding to SASS files stops the error from occurring and lets the page load. However, if we do so:
The home page then has tons of links to /stylesheets/___.css, which result in 404’s, instead of the correct /assets/____.css as it does for me.
What we tried:
I tried stepping through loading the homepage on both our machines with debugger. Our code execution diverged here:
.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
Specifically, the statement asset_paths.asset_for(source, 'css') raises an error for my colleague, but not for me.
We also tried uninstalling and reinstalling rails and rvm.
Oh, feels stupid… we fixed it.
rm -rf‘ing the entire directory and re-cloning it fixed it. I guess there was an extra file in there floating around or something.