| description | Form validations in five minutes or it's free |
|---|
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.
bundle add optimism
yarn add cable_ready
rake optimism:installThe 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 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.
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" %}
# :debug, :info, :warn, :error, :fatal, :unknown
config.log_level = :warn{% endcode %}
{% 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:
pkill -f springbundle remove spring spring-watcher-listen --installbin/spring binstub -remove -all{% endhint %}