|
| 1 | +# Configuration |
| 2 | + |
| 3 | +Inertia Rails can be configured globally or in a specific controller (and subclasses). |
| 4 | + |
| 5 | +## Global Configuration |
| 6 | + |
| 7 | +If using global configuration, we recommend you place the code inside an initializer: |
| 8 | + |
| 9 | +```ruby |
| 10 | +# config/initializers/inertia.rb |
| 11 | + |
| 12 | +InertiaRails.configure do |config| |
| 13 | + # Example: force a full-reload if the deployed assets change. |
| 14 | + config.version = ViteRuby.digest |
| 15 | +end |
| 16 | +``` |
| 17 | + |
| 18 | +The default configuration can be found [here](https://github.com/inertiajs/inertia-rails/blob/master/lib/inertia_rails/configuration.rb#L5). |
| 19 | + |
| 20 | +## Local Configuration |
| 21 | + |
| 22 | +Use `inertia_config` in your controllers to override global settings: |
| 23 | + |
| 24 | +```ruby |
| 25 | +class EventsController < ApplicationController |
| 26 | + inertia_config( |
| 27 | + version: "events-#{InertiaRails.configuration.version}", |
| 28 | + ssr_enabled: -> { action_name == "index" }, |
| 29 | + ) |
| 30 | +end |
| 31 | +``` |
| 32 | + |
| 33 | +## Configuration Options |
| 34 | + |
| 35 | +### `component_path_resolver` |
| 36 | + |
| 37 | +Use `component_path_resolver` to customize component path resolution when [`default_render`](#default_render) config value is set to `true`. The value should be callable and will receive the `path` and `action` parameters, returning a string component path. See [Automatically determine component name](/guide/responses#automatically-determine-component-name). |
| 38 | + |
| 39 | +**Default**: `->(path:, action:) { "#{path}/#{action}" }` |
| 40 | + |
| 41 | +### `deep_merge_shared_data` |
| 42 | + |
| 43 | +When enabled, props will be deep merged with shared data, combining hashes |
| 44 | +with the same keys instead of replacing them. |
| 45 | + |
| 46 | +**Default**: `false` |
| 47 | + |
| 48 | +### `default_render` |
| 49 | + |
| 50 | +Overrides Rails default rendering behavior to render using Inertia by default. |
| 51 | + |
| 52 | +**Default**: `false` |
| 53 | + |
| 54 | +### `encrypt_history` |
| 55 | + |
| 56 | +When enabled, you instruct Inertia to encrypt your app's history, it uses |
| 57 | +the browser's built-in [`crypto` api](https://developer.mozilla.org/en-US/docs/Web/API/Crypto) |
| 58 | +to encrypt the current page's data before pushing it to the history state. |
| 59 | + |
| 60 | +**Default**: `false` |
| 61 | + |
| 62 | +### `ssr_enabled` _(experimental)_ |
| 63 | + |
| 64 | +Whether to use a JavaScript server to pre-render your JavaScript pages, |
| 65 | +allowing your visitors to receive fully rendered HTML when they first visit |
| 66 | +your application. |
| 67 | + |
| 68 | +Requires a JS server to be available at `ssr_url`. [_Example_](https://github.com/ElMassimo/inertia-rails-ssr-template) |
| 69 | + |
| 70 | +**Default**: `false` |
| 71 | + |
| 72 | +### `ssr_url` _(experimental)_ |
| 73 | + |
| 74 | +The URL of the JS server that will pre-render the app using the specified |
| 75 | +component and props. |
| 76 | + |
| 77 | +**Default**: `"http://localhost:13714"` |
| 78 | + |
| 79 | +### `version` _(recommended)_ |
| 80 | + |
| 81 | +This allows Inertia to detect if the app running in the client is oudated, |
| 82 | +forcing a full page visit instead of an XHR visit on the next request. |
| 83 | + |
| 84 | +See [assets versioning](https://inertiajs.com/asset-versioning). |
| 85 | + |
| 86 | +**Default**: `nil` |
0 commit comments