Skip to content

Instantly share code, notes, and snippets.

Created June 20, 2014 06:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5737b58edb271428ffdd to your computer and use it in GitHub Desktop.
Save anonymous/5737b58edb271428ffdd to your computer and use it in GitHub Desktop.
Rails selective loading of assets based on current controller/action name
def load_assets
@stylesheets, @javascripts = [], []
[controller_path, "#{controller_path}/#{action_name}"].each do |i|
@stylesheets << "pages/#{i}" if File.exists? "#{Rails.root}/app/assets/stylesheets/pages/#{i}.css.scss"
@javascripts << "pages/#{i}" if File.exists? "#{Rails.root}/app/assets/javascripts/pages/#{i}.js.coffee"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment