Less Known ‘rails commands’

Rails developers all use some or many of these commands like

rails g or rails generate

to run an official or custom generator

rails d or rails destroy

to revert back newly created code/scaffold etc

rails routes

you all know it well.

rails assets:precompile
rails application_record
rails assets
rails rails rails channel
rails controller
rails generator
rails helper
rails integration_test
rails jbuilder
rails job
rails mailer
rails migration
rails model
rails resource
rails responders_controller
rails scaffold
rails scaffold_controller
rails serializer
rails system_test
rails task

And more related to ActiveRecord and Tests.

But there are some more less known/used which can be helpful too in some cases


rails console --sandbox
Any modifications you make will be rolled back on exit of session.

rails dbconsole
Connects to underlying database using adapter, we can pass environment variable with -e option as we do in rails c -e production

rails about
This command will show following information about our application

Rails version
Ruby version along with OS
RubyGems version
Rack version
JavaScript Runtime
Application root
Database adapter
Database schema version


rails stats (My Favorite 🙂 )
Quick summary of the lines of code, lines of test code, number of classes, number of methods, the ratio of methods to classes, and the ratio of lines of code per method.

There is “Code to Test Ratio” at the end of output if that is anything less than 1:1 that is an indication that our application lacks sufficient tests.

rails notes
Will search form comments you wrote starting with “TODO”, “FIXME” or “OPTIMIZE” in
all (.rb, .erb, .rake, .css, .js, .ruby, .yml, .yaml, .bundler) files.

By default this command will only look in the app, config, db, lib and test directories.

we can configure this by

rails notes #prints all containing any of the words
rails notes:todo #prints only TODO, you can pass any of three

This is useful if you need to know where you want to work later or optimize a code block.

rails tmp:clear

rails tmp:cache:clear

rails tmp:sockets:clear

rails tmp:screenshots:clear

These commands clears all, clears cache only, clears sockets only and clears screenshots only respectively

& The last but not least in the list is

rails time:zones:all
shows all known timezones to rails. That’s all, hope you enjoyed and learned something.

If you know any other, please share in comments I’ll include that here.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s