How to Create Sprite Images using Compass Rails Gem in Rails 4.2.5
Create a new rails project.
Copy icons to
Create a sprites folder in
compass-rails to Gemfile. Run:
Create your resource.
rails g scaffold article title:string content:text
Add, the following to
@import "compass/utilities/sprites"; @import "icons/*.png"; @include all-icons-sprites;
Read the compass gem home page to learn more about these declarations.
production.rb, enable assets and configure the folder where the generated sprite images should be stored.
config.assets.enabled = true config.compass.generated_images_dir = “app/assets/images/sprites”
You can also add it to
development.rb for testing locally in development environment.
You will see the generated sprite file in
app/assets/images/sprites folder. Add
Sample source code can be downloaded from
In this article, you learned how to use compass-rails gem to generate sprite images for Rails 4.2.5 apps. It reduces the number of files to download from a server and therefore improves the performance.