# Setup

## Setup

Optimism has a relatively small number of dependencies, but it does assume that it's being run in a Rails project with ActionCable configured for the environments you intend to operate in. You can easily install Optimism to new and existing Rails projects.

```bash
bundle add optimism
yarn add cable_ready
rake optimism:install
```

The terminal commands above will ensure that Optimism is installed. It creates the client-side websocket channel infrastructure required to process the list of commands from the server. All of this is possible because it's built on the shoulders of the incredible [CableReady](https://cableready.stimulusreflex.com/) gem, which gives developers the ability to tweak many different aspects of the current page from the server.

**Anyhow\... that's it: you're ready to start integrating Optimism into your user interfaces**.

![](https://799330481-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0jDsloEnsaUCKRlSJL%2F-M0pKFWjq1zmNhdt2Kko%2F-M0pcFZJu2g-mm1siEx6%2Fsetup.svg?alt=media\&token=9a64a386-e232-489e-9a0d-ca5a5792f84a)

## Authentication

{% hint style="info" %}
If you're just experimenting with Optimism or trying to bootstrap a proof-of-concept application on your local workstation, you can actually skip this section until you're planning to deploy.
{% endhint %}

Out of the box, ActionCable doesn't give Optimism the ability to distinguish between multiple concurrent users looking at the same page.

**If you deploy to a host with more than one person accessing your app, you'll find that you're sharing a session and seeing other people's updates.** That isn't what most developers have in mind!

When the time comes, it's easy to configure your application to support authenticating users by their Rails session or current\_user scope. Just check out the Authentication page and choose your own adventure.

{% content-ref url="authentication" %}
[authentication](https://optimism.leastbad.com/authentication)
{% endcontent-ref %}

## Logging

In the default *debug* log level, ActionCable emits particularly verbose log messages. You can optionally discard everything but exceptions by switching to the *warn* log level, as is common in development environments:

{% code title="config/environments/development.rb" %}

```ruby
# :debug, :info, :warn, :error, :fatal, :unknown
config.log_level = :warn
```

{% endcode %}

## Troubleshooting

{% hint style="info" %}
If *something* goes wrong, it's often because of the **spring** gem. You can test this by temporarily setting the `DISABLE_SPRING=1` environment variable and restarting your server.

To remove **spring** forever, here is the process we recommend:

1. `pkill -f spring`
2. `bundle remove spring spring-watcher-listen --install`
3. `bin/spring binstub -remove -all`
   {% endhint %}


---

# Agent Instructions: 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://optimism.leastbad.com/setup.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.
