Prevent Writes With A Sandboxed Rails Console
I often open a rails console
to play around with some data and make sure I understand how some models can be instantiated while respecting their associations. There are plenty of times where I've created some data in the development
database that doesn't need to be there. It may even be incomplete data from a failed experiment.
This data accumlates and clutters up the database.
One way to avoid this is by running the console in a sandboxed mode. Include the --sandbox
flag when starting up a session to do this.
This wraps the session in a transaction so that any writes to the database can be rolledback afterward.
Last updated