Skip to content

Instantly share code, notes, and snippets.

@soychicka
Last active February 3, 2018 23:41
Show Gist options
  • Save soychicka/82f5b209603f834c36b391e2b56d4c90 to your computer and use it in GitHub Desktop.
Save soychicka/82f5b209603f834c36b391e2b56d4c90 to your computer and use it in GitHub Desktop.
Rails 5 - allow direct requests of all assets w/o specifying in manifest. NOT scalable
#### config/initializers/assets.rb
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile << Proc.new { |path|
if path =~ /\.(css|js)\z/
@assets ||= Rails.application.assets || Sprockets::Railtie.build_environment(Rails.application)
full_path = @assets.resolve(path)
app_assets_path = Rails.root.join('app', 'assets').to_path
if full_path.starts_with? app_assets_path
puts "including: " + full_path
true
else
false
end
else
false
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment