> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/prevent-writes-with-a-sandboxed-rails-console.md).

# 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.

```bash
$ rails console --sandbox
Loading development environment in sandbox (Rails 5.2.6)
Any modifications you make will be rolled back on exit
[1] pry(main)>
```

This wraps the session in a transaction so that any writes to the database can be rolledback afterward.

[source](https://dev.to/citizen428/rails-quick-tips-1-console-sandbox-4k0c)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/prevent-writes-with-a-sandboxed-rails-console.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
