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.
Ace the Technical Interview
- Easily find the gaps in your knowledge
- Get customized lessons based on where you are
- Take consistent action everyday
- Builtin accountability to keep you on track
- You will solve bigger problems over time
- Get the job of your dreams
Take the 30 Day Coding Skills Challenge
Gain confidence to attend the interview