feat: support multiple inertia apps by allowing different layouts #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description 📖
This pull request allows to leverage the default layout resolution in Rails.
Background 📜
When using Rails as the backend for different Inertia apps, having a global layout configuration does not allow each app to have a different layout (with different title and meta tags, for example).
By using the layout specified by the controller (which defaults to
application
in most apps), the user has more flexibility to choose which layout should be used.For example, this pull request enables:
where the
admin
frontend app gets its own layout, with different scripts, meta tags, and title.Notes ✏️
The previous mechanism to configure a layout is still supported:
An internal
inertia_layout
controller instance method was added for the purpose of even more dynamic configurations, for users that need the flexibility. Now they can customize the behavior by defining a method in their controllers, without having to monkey-patchInertiaRails
.Considerations about Backwards Compatibility
This shouldn't be considered a breaking change, as the default layout for most Rails apps is
application
(hence, the tests didn't need to be updated), and in other setups, a user would already be configuringInertiaRails::Configuration#layout
explicitly, which will continue to work.