Skip to content

Instantly share code, notes, and snippets.

@kattak
Last active June 19, 2018 23:51
Show Gist options
  • Save kattak/a305850eefd10c6a34062bee684129f6 to your computer and use it in GitHub Desktop.
Save kattak/a305850eefd10c6a34062bee684129f6 to your computer and use it in GitHub Desktop.

#Rails 5 Asset Pipeline

##Solution Use this gem: https://github.com/heroku/rails_12factor

##Why/What does this gem do? Read here: heroku/rails_12factor#3

##Why use SCSS for Rails 5 apps? Rails comes equipped with Sass by default. (It's in the Gemfile)

In Gemfile:

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
  • Can you use CSS and SCSS for Rails 5 app?

#application.css -Master stylesheet in the Rails Asset Pipeline

In app/assets/stylesheets/application.css

  *= require_self
  *= require_tree .

-Means CSS in application.css will overwrite any other CSS, including imported CSS

Organizing CSS & SASS in Rails: http://www.mattboldt.com/organizing-css-and-sass-rails/

#From Rails Guide The asset pipeline is implemented by the sprockets-rails gem, and is enabled by default. You can disable it while creating a new application by passing the --skip-sprockets option.

  • In application.css.erb
.class { background-image: url(<%= asset_path 'image.png' %>) }

"If this image is already available in public/assets as a fingerprinted file, then that path is referenced."

2.3.2 CSS and Sass When using the asset pipeline, paths to assets must be re-written and sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.

image-url("rails.png") returns url(/assets/rails.png) image-path("rails.png") returns "/assets/rails.png" The more generic form can also be used:

asset-url("rails.png") returns url(/assets/rails.png) asset-path("rails.png") returns "/assets/rails.png"

4.3 Live Compilation In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly.

To enable this option set:

config.assets.compile = true

Since jQuery is the default JavaScript library from Rails 3.1 onwards, you don't need to copy jquery.js into app/assets and it will be included automatically.

#Remaining Questions Where is background-image property in inspect? http://lyricallychallenged.herokuapp.com/ Max: As a minified file somewhere in your sources.

@waleolakareem
Copy link

waleolakareem commented Jun 19, 2018

Thank you for this, worked for me

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