Skip to content

Instantly share code, notes, and snippets.

@iwinux
Created December 28, 2011 18:38
Show Gist options
  • Save iwinux/1529093 to your computer and use it in GitHub Desktop.
Save iwinux/1529093 to your computer and use it in GitHub Desktop.
config.assets.precompile
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 ]
@wchrisjohnson
Copy link

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

@iwinux
Copy link
Author

iwinux commented Mar 16, 2012

@cjohnson I put these into the production.rb

@bkempner
Copy link

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:inblock in <top (required)>'

@logicalhan
Copy link

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

@swrobel
Copy link

swrobel commented Oct 26, 2012

Thank you! 👏

@okliv
Copy link

okliv commented Nov 9, 2013

just amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment