DEV Community

Subash
Subash

Posted on

Rails console sandbox mode

rails c or rails console starts the irb session, where we can execute, test and confirm queries. It is one of the helpful feature for developers. However we need to use it with caution as it is capable of modifying records. Any accidental modification in staging or production data might lead to problem.

There is an option to avoid this. Rails comes with an inbuilt sandbox mode. When you start the console with --sanbox flag, we will see a message Any modifications you make will be rolled back on exit because the whole irb session starts within an ActiveRecord::Transaction, which is rolled back when you exit the session.

Here's a sample

rails console in sandbox mode

But wait, There is a catch

In sandbox mode, database rows are fully locked, which means that it prevents your live production services from modifying them. If you are holding a record for too long, all the live transactions related to it have to wait till the lock is released or in some cases might mess up the updations.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay