How to Delete Unused images from Rails Application

By: Aachal Tayade Category: Ruby on Rails Technologies: Ruby on Rails

In a Rails application, unnecessary images will affect application load time and also slow down your test and deploy pipeline.

One of my recent projects was to try to identify the unused images and remove them safely. It was quite a difficult task in the application to find images that were not in use.

Really It’s hard to check if you’re not using each one of them, so you can use the below Rake task to flush out all the unused images and delete them.

So Here is a Rake task to find unused images in the Rails project to deletion.

1) How to Create Rake task?

Command: rails g task <namespace> <taskname>

For Eg: rails g task image_cleaner find_unused_images

rake file will generate inside the “lib/tasks” folder.

Rake file body:

How to execute?

Run below rake task command in your project directory terminal:

Execution result:

As for me, I have successfully deleted unused images by using the above rake task without breaking anything. hopefully, now you would love to delete all the images in your app/assets/images folder that you don't use.

Hope this helps!

Thanks for reading.

Originally published at



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cryptex Technologies

Cryptex specializes in developing open source web applications and software solutions across all domains and verticals using Ruby on Rails (ROR) technology