Skip to content

Add inertia_rendering? method and set instance variable in renderer #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025

Conversation

Andy9822
Copy link
Contributor

@Andy9822 Andy9822 commented Apr 7, 2025

We are introducing a new method inertia_rendering? in the InertiaRails helper to check if the controller is currently rendering an Inertia response.
This allow a view to conditionally render something based on this option i.e. the layout may include the inertia pack based on this.

P.S. ideally, this could be subtly mentioned somewhere in the docs but I'm new here so I'll leave that up to you (although Im open to add it if you have a suggestion on where and how to word it if you want)

Closes #208

Andy9822 added 2 commits April 7, 2025 18:07
We are introducing a new method `inertia_rendering?` in the `InertiaRails` helper to check if the controller is currently rendering an Inertia response.
This allow a view to conditionally render something based on this option i.e. the layout may include the `inertia` pack based on this.
@Andy9822
Copy link
Contributor Author

Andy9822 commented Apr 7, 2025

I'm not completely sure with the testing approach I've implemented for this helper. The current test directly extends the controller with InertiaRails::Helper, but this doesn't accurately reflect how the helper is actually included in a Rails application.

In the real application, the helper is included indirectly through InertiaRails::Controller, which is then injected into ActionController::Base via Rails' on_load hook during initialization.

@Andy9822 Andy9822 changed the title Add inertia_rendering? method and set instance variable in renderer Add inertia_rendering? method and set instance variable in renderer Apr 7, 2025
Copy link
Contributor

@skryukov skryukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, @bknoles could you help merging this?

@bknoles bknoles merged commit 4ceb8c3 into inertiajs:master Apr 10, 2025
17 checks passed
@bknoles
Copy link
Collaborator

bknoles commented Apr 10, 2025

Merged! I'd like to release after we get the deep merge stuff merged in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Determine whether a view template is being rendered by the inertia custom renderer
3 participants