Skip to content

Commit eb169df

Browse files
authored
Merge pull request #231 from skryukov/parent-controller-config
Add `parent_controller` config option
2 parents b692b92 + c7489af commit eb169df

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

app/controllers/inertia_rails/static_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module InertiaRails
2-
class StaticController < ::ApplicationController
2+
class StaticController < InertiaRails.configuration.parent_controller.constantize
33
def static
44
render inertia: params[:component]
55
end

docs/guide/configuration.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,57 +30,78 @@ class EventsController < ApplicationController
3030
end
3131
```
3232

33+
## Setting Configuration via Environment Variables
34+
35+
Inertia Rails supports setting any configuration option via environment variables out of the box. For each option in the configuration, you can set an environment variable prefixed with `INERTIA_` and the option name in uppercase. For example: `INERTIA_SSR_ENABLED`.
36+
37+
**Boolean values** (like `INERTIA_DEEP_MERGE_SHARED_DATA` or `INERTIA_SSR_ENABLED`) are parsed from the strings `"true"` or `"false"` (case-sensitive).
38+
3339
## Configuration Options
3440

3541
### `component_path_resolver`
3642

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-
3943
**Default**: `->(path:, action:) { "#{path}/#{action}" }`
4044

45+
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).
46+
4147
### `deep_merge_shared_data`
4248

49+
**Default**: `false`
50+
**ENV**: `INERTIA_DEEP_MERGE_SHARED_DATA`
51+
4352
When enabled, props will be deep merged with shared data, combining hashes
4453
with the same keys instead of replacing them.
4554

46-
**Default**: `false`
47-
4855
### `default_render`
4956

50-
Overrides Rails default rendering behavior to render using Inertia by default.
57+
**Default**: `false`
58+
**ENV**: `INERTIA_DEFAULT_RENDER`
5159

52-
**Default**: `false`
60+
Overrides Rails default rendering behavior to render using Inertia by default.
5361

5462
### `encrypt_history`
5563

64+
**Default**: `false`
65+
**ENV**: `INERTIA_ENCRYPT_HISTORY`
66+
5667
When enabled, you instruct Inertia to encrypt your app's history, it uses
5768
the browser's built-in [`crypto` api](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)
5869
to encrypt the current page's data before pushing it to the history state.
5970

60-
**Default**: `false`
61-
6271
### `ssr_enabled` _(experimental)_
6372

73+
**Default**: `false`
74+
**ENV**: `INERTIA_SSR_ENABLED`
75+
6476
Whether to use a JavaScript server to pre-render your JavaScript pages,
6577
allowing your visitors to receive fully rendered HTML when they first visit
6678
your application.
6779

6880
Requires a JS server to be available at `ssr_url`. [_Example_](https://github.com/ElMassimo/inertia-rails-ssr-template)
6981

70-
**Default**: `false`
71-
7282
### `ssr_url` _(experimental)_
7383

84+
**Default**: `"http://localhost:13714"`
85+
**ENV**: `INERTIA_SSR_URL`
86+
7487
The URL of the JS server that will pre-render the app using the specified
7588
component and props.
7689

77-
**Default**: `"http://localhost:13714"`
78-
7990
### `version` _(recommended)_
8091

92+
**Default**: `nil`
93+
**ENV**: `INERTIA_VERSION`
94+
8195
This allows Inertia to detect if the app running in the client is oudated,
8296
forcing a full page visit instead of an XHR visit on the next request.
8397

84-
See [assets versioning](https://inertiajs.com/asset-versioning).
98+
See [assets versioning](/guide/asset-versioning).
8599

86-
**Default**: `nil`
100+
### `parent_controller`
101+
102+
**Default**: `'::ApplicationController'`
103+
**ENV**: `INERTIA_PARENT_CONTROLLER`
104+
105+
Specifies the base controller class for the internal `StaticController` used to render [Shorthand routes](/guide/routing#shorthand-routes).
106+
107+
By default, Inertia Rails creates a `StaticController` that inherits from `ApplicationController`. You can use this option to specify a different base controller (for example, to include custom authentication, layout, or before actions).

lib/inertia_rails/configuration.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Configuration
2525

2626
# Used to detect version drift between server and client.
2727
version: nil,
28+
29+
# Allows configuring the base controller for StaticController
30+
parent_controller: '::ApplicationController',
2831
}.freeze
2932

3033
OPTION_NAMES = DEFAULTS.keys.freeze

0 commit comments

Comments
 (0)