public
Last active

config.assets.precompile

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
def compile_asset?(path)
# ignores any filename that begins with '_' (e.g. sass partials)
# all other css/js/sass/image files are processed
if File.basename(path) =~ /^[^_].*\.\w+$/
puts "Compiling: #{path}"
true
else
puts "Ignoring: #{path}"
false
end
end
 
config.assets.precompile = [ method(:compile_asset?).to_proc ]

And since rake assets:precompile gives no indicator of the compilation progress, I think it great to print these Compiling and Ignoring lines.

Forgive the ignorance, but where would this method go? Inside the env file itself?

@cjohnson I put these into the production.rb

Doesn't work for me at all when deploying on heroku. I pasted in my production.rb

2012-03-29T18:19:47+00:00 app[web.1]: /app/config/environments/production.rb:27:in method': undefined methodcompile_asset?' for class Class' (NameError)
2012-03-29T18:19:47+00:00 app[web.1]: from /app/config/environments/production.rb:27:in
block in '

try putting the method in the outer scope:

 #the absolute beginning of the production.rb file
def compile_asset?(path)
  if File.basename(path) =~ /^[^_].*\.\w+$/
    puts "Compiling: #{path}"
    true
  else
    puts "Ignoring: #{path}"
    false
  end
end
SomeApplicationName::Application.configure do
   config.assets.precompile = [ method(:compile_asset?).to_proc ]
#...some other config stuff
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.