Skip to content

Commit ebca314

Browse files
committed
Use CoC renderer for docs
1 parent 006f942 commit ebca314

File tree

11 files changed

+79
-64
lines changed

11 files changed

+79
-64
lines changed

docs/cookbook/inertia-modal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ To define the base route for your modal, you need to use the `inertia_modal` ren
260260

261261
class UsersController < ApplicationController
262262
def edit
263-
render inertia: 'Users/Edit', props: { # [!code --]
264-
render inertia_modal: 'Users/Edit', props: { # [!code ++]
263+
render inertia: { # [!code --]
264+
render inertia_modal: { # [!code ++]
265265
user:,
266266
roles: -> { Role.all },
267267
}
@@ -275,7 +275,7 @@ Then, you can pass the `base_url` parameter to the `inertia_modal` renderer to d
275275

276276
class UsersController < ApplicationController
277277
def edit
278-
render inertia_modal: 'Users/Edit', props: {
278+
render inertia_modal: {
279279
user:,
280280
roles: -> { Role.all },
281281
} # [!code --]

docs/cookbook/server-managed-meta-tags.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class EventsController < ApplicationController
212212
def show
213213
event = Event.find(params[:id])
214214

215-
render inertia: 'Event/Show', props: { event: event.as_json }, meta: [
215+
render inertia: { event: event.as_json }, meta: [
216216
{ title: "Check out the #{event.name} event!" },
217217
{ name: 'description', content: event.description },
218218
{ tag_name: 'script', type: 'application/ld+json', inner_content: { '@context': 'https://schema.org', '@type': 'Event', name: 'My Event' } }
@@ -232,7 +232,7 @@ class EventsController < ApplicationController
232232
before_action :set_meta_tags
233233

234234
def show
235-
render inertia: 'Event/Show', props: { event: Event.find(params[:id]) }
235+
render inertia: { event: Event.find(params[:id]) }
236236
end
237237

238238
private
@@ -319,12 +319,12 @@ class StoriesController < ApplicationController
319319

320320
# Renders a single article:author meta tag
321321
def single_author
322-
render inertia: 'Stories/Show'
322+
render inertia: 'stories/show'
323323
end
324324

325325
# Renders multiple article:author meta tags
326326
def multiple_authors
327-
render inertia: 'Stories/Show', meta: [
327+
render inertia: 'stories/show', meta: [
328328
{ name: 'article:author', content: 'Dan Gilroy', allow_duplicates: true },
329329
]
330330
end

docs/guide/authorization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Here's an example of how you might do this in a Rails controller using the [Acti
99
```ruby
1010
class UsersController < ApplicationController
1111
def index
12-
render inertia: 'Users/Index', props: {
12+
render inertia: {
1313
can: {
1414
create_user: allowed_to?(:create, User)
1515
},

docs/guide/deferred-props.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To defer a prop, you can use the `InertiaRails.defer` method when returning your
1111
```ruby
1212
class UsersController < ApplicationController
1313
def index
14-
render inertia: 'Users/Index', props: {
14+
render inertia: {
1515
users: -> { User.all },
1616
roles: -> { Role.all },
1717
permissions: InertiaRails.defer { Permission.all },
@@ -27,7 +27,7 @@ By default, all deferred props get fetched in one request after the initial page
2727
```ruby
2828
class UsersController < ApplicationController
2929
def index
30-
render inertia: 'Users/Index', props: {
30+
render inertia: {
3131
users: -> { User.all },
3232
roles: -> { Role.all },
3333
permissions: InertiaRails.defer { Permission.all },

docs/guide/history-encryption.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ If you'd like to enable history encryption globally, set the `encrypt_history` c
2222
You are able to opt out of encryption on specific pages by passing `false` to the `encrypt_history` option.
2323

2424
```ruby
25-
render inertia: 'Homepage', props: {}, encrypt_history: false
25+
render inertia: {}, encrypt_history: false
2626
```
2727

2828
### Per-request encryption
2929

3030
To encrypt the history of an individual request, simply pass `true` to the `encrypt_history` option.
3131

3232
```ruby
33-
render inertia: 'Dashboard', props: {}, encrypt_history: true
33+
render inertia: {}, encrypt_history: true
3434
```
3535

3636
### Controller-level encryption
@@ -50,7 +50,7 @@ end
5050
To clear the history state on the server side, you can pass the `clear_history` option to the `render` method.
5151

5252
```ruby
53-
render inertia: 'Dashboard', props: {}, clear_history: true
53+
render inertia: {}, clear_history: true
5454
```
5555

5656
Once the response has rendered on the client, the encryption key will be rotated, rendering the previous history state unreadable.

docs/guide/pages.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ export default function Welcome({ user }) {
8585

8686
:::
8787

88-
Given the page above, you can render the page by returning an Inertia response from a controller or route. In this example, let's assume this page is stored at `app/frontend/pages/User/Show.(jsx|vue|svelte)` within a Rails application.
88+
Given the page above, you can render the page by returning an Inertia response from a controller or route. In this example, let's assume this page is stored at `app/frontend/pages/user/show.(jsx|vue|svelte)` within a Rails application.
8989

9090
```ruby
9191
class UsersController < ApplicationController
9292
def show
9393
user = User.find(params[:id])
9494

95-
render inertia: 'User/Show', props: { user: }
95+
render inertia: { user: }
9696
end
9797
end
9898
```

docs/guide/partial-reloads.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ For partial reloads to be most effective, be sure to also use lazy data evaluati
210210
```ruby
211211
class UsersController < ApplicationController
212212
def index
213-
render inertia: 'Users/Index', props: {
213+
render inertia: {
214214
users: -> { User.all },
215215
companies: -> { Company.all },
216216
}
@@ -225,7 +225,7 @@ Additionally, Inertia provides an `InertiaRails.optional` method to specify that
225225
```ruby
226226
class UsersController < ApplicationController
227227
def index
228-
render inertia: 'Users/Index', props: {
228+
render inertia: {
229229
users: InertiaRails.optional { User.all },
230230
}
231231
end
@@ -240,7 +240,7 @@ On the inverse, you can use the `InertiaRails.always` method to specify that a p
240240
```ruby
241241
class UsersController < ApplicationController
242242
def index
243-
render inertia: 'Users/Index', props: {
243+
render inertia: {
244244
users: InertiaRails.always { User.all },
245245
}
246246
end
@@ -252,7 +252,7 @@ Here's a summary of each approach:
252252
```ruby
253253
class UsersController < ApplicationController
254254
def index
255-
render inertia: 'Users/Index', props: {
255+
render inertia: {
256256
# ALWAYS included on standard visits
257257
# OPTIONALLY included on partial reloads
258258
# ALWAYS evaluated

docs/guide/responses.md

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,61 @@
22

33
## Creating responses
44

5-
Creating an Inertia response is simple. To get started, just use the `inertia` renderer in your controller methods, providing both the name of the [JavaScript page component](/guide/pages.md) that you wish to render, as well as any props (data) for the page.
5+
Creating an Inertia response is simple. By default, Inertia Rails follows convention over configuration: you simply pass the props (data) you wish to send to the page, and the component name is automatically inferred from the controller and action.
66

77
```ruby
8-
class EventsController < ApplicationController
8+
class UsersController < ApplicationController
99
def show
10-
event = Event.find(params[:id])
11-
12-
render inertia: 'Event/Show', props: {
13-
event: event.as_json(
14-
only: [:id, :title, :start_date, :description]
15-
)
16-
}
10+
user = User.find(params[:id])
11+
render inertia: { user: } # Renders '../users/show.jsx|vue|svelte'
1712
end
1813
end
1914
```
2015

21-
Within Rails applications, the `Event/Show` page would typically correspond to the file located at `app/frontend/pages/Event/Show.(jsx|vue|svelte)`.
16+
Within Rails applications, the `UsersController#show` action would typically correspond to the file located at `app/frontend/pages/users/show.(jsx|vue|svelte)`.
2217

2318
> [!WARNING]
2419
> To ensure that pages load quickly, only return the minimum data required for the page. Also, be aware that **all data returned from the controllers will be visible client-side**, so be sure to omit sensitive information.
2520
26-
### Automatically determine component name
21+
### Customizing the Component Path
22+
23+
While the default convention works for most cases, you may need to render a specific component or change how component paths are resolved globally.
2724

28-
You can pass props without specifying a component name:
25+
#### Explicit Component Names
26+
27+
If you wish to render a component that does not match the current controller action, you can explicitly provide the name of the [JavaScript page component](/guide/pages) followed by the props hash.
2928

3029
```ruby
31-
class UsersController < ApplicationController
32-
def show
33-
render inertia: { user: @user } # Will render '../users/show.jsx|vue|svelte'
30+
class EventsController < ApplicationController
31+
def my_event
32+
event = Event.find(params[:id])
33+
34+
render inertia: 'events/show', props: {
35+
event: event.as_json(
36+
only: [:id, :title, :start_date, :description]
37+
)
38+
}
3439
end
3540
end
3641
```
3742

38-
If the default component path doesn't match your convention, you can define a custom resolution method via the `component_path_resolver` config value. The value should be callable and will receive the path and action parameters, returning a string component path.
43+
#### Custom Path Resolver
44+
45+
If the default automatic path resolution does not match your project's conventions, you can define a custom resolution method via the `component_path_resolver` config value.
46+
47+
The value should be callable and will receive the `path` and `action` parameters, returning a string component path.
3948

4049
```ruby
4150
inertia_config(
4251
component_path_resolver: ->(path:, action:) do
43-
"Storefront/#{path.camelize}/#{action.camelize}"
52+
"storefront/#{path.camelize}/#{action.camelize}"
4453
end
4554
)
4655
```
4756

4857
### Using instance variables as props
4958

50-
Inertia enables the automatic passing of instance variables as props. This can be achieved by invoking the `use_inertia_instance_props` function in a controller or in a base controller from which other controllers inherit.
59+
For convenience, Inertia can automatically pass your controller's instance variables to the page component as props. To enable this behavior, invoke the `use_inertia_instance_props` method within your controller or a base controller.
5160

5261
```ruby
5362
class EventsController < ApplicationController
@@ -56,18 +65,24 @@ class EventsController < ApplicationController
5665
def index
5766
@events = Event.all
5867

59-
render inertia: 'Events/Index'
68+
render inertia: 'events/index'
6069
end
6170
end
6271
```
6372

64-
This action automatically passes the `@events` instance variable as the `events` prop to the `Events/Index` page component.
73+
In this example, the `@events` instance variable is automatically included in the response as the `events` prop.
6574

66-
> [!NOTE]
67-
> Manually providing any props for a response disables the instance props feature for that specific response.
75+
Please note that if you manually provide a props hash in your render call, the instance variables feature is disabled for that specific response.
6876

69-
> [!NOTE]
70-
> Instance props are only included if they are defined **after** the `use_inertia_instance_props` call, hence the order of `before_action` callbacks is crucial.
77+
> [!WARNING]
78+
> Security and Performance Risk
79+
>
80+
> When enabled, this feature serializes all instance variables present in the controller at the time of rendering. This includes:
81+
> * Variables set by `before_action` filters (e.g., `@current_user`, `@breadcrumbs`) called **after** `use_inertia_instance_props`.
82+
> * Memoized variables (often used for caching internal state, e.g., `@_cached_result`).
83+
> * Variables intended only for server-side logic.
84+
>
85+
> This creates a high risk of accidentally leaking sensitive data or internal implementation details to the client. It can also negatively impact performance by serializing unnecessary heavy objects. We recommend being explicit with your props whenever possible.
7186
7287
## Root template data
7388

@@ -89,7 +104,7 @@ Sometimes you may even want to provide data to the root template that will not b
89104
def show
90105
event = Event.find(params[:id])
91106

92-
render inertia: 'Event', props: { event: }, view_data: { meta: event.meta }
107+
render inertia: { event: }, view_data: { meta: event.meta }
93108
end
94109
```
95110

@@ -134,13 +149,13 @@ $ bin/rails generate inertia:scaffold Post title:string body:text
134149
invoke scaffold_controller
135150
create app/controllers/posts_controller.rb
136151
invoke inertia_templates
137-
create app/frontend/pages/Post
138-
create app/frontend/pages/Post/Index.svelte
139-
create app/frontend/pages/Post/Edit.svelte
140-
create app/frontend/pages/Post/Show.svelte
141-
create app/frontend/pages/Post/New.svelte
142-
create app/frontend/pages/Post/Form.svelte
143-
create app/frontend/pages/Post/Post.svelte
152+
create app/frontend/pages/posts
153+
create app/frontend/pages/posts/index.svelte
154+
create app/frontend/pages/posts/edit.svelte
155+
create app/frontend/pages/posts/show.svelte
156+
create app/frontend/pages/posts/new.svelte
157+
create app/frontend/pages/posts/form.svelte
158+
create app/frontend/pages/posts/post.svelte
144159
invoke resource_route
145160
invoke test_unit
146161
create test/controllers/posts_controller_test.rb
@@ -178,9 +193,9 @@ $ bin/rails generate inertia:controller pages welcome next_steps
178193
create app/helpers/pages_helper.rb
179194
invoke test_unit
180195
invoke inertia_templates
181-
create app/frontend/pages/Pages
182-
create app/frontend/pages/Pages/Welcome.jsx
183-
create app/frontend/pages/Pages/NextSteps.jsx
196+
create app/frontend/pages/pages
197+
create app/frontend/pages/pages/welcome.jsx
198+
create app/frontend/pages/pages/next_steps.jsx
184199
```
185200

186201
### Customizing the generator templates
@@ -235,7 +250,7 @@ Inertia responses always operate as a `:html` response type. This means that you
235250
def some_action
236251
respond_to do |format|
237252
format.html do
238-
render inertia: 'Some/Component', props: { data: 'value' }
253+
render inertia: { data: 'value' }
239254
end
240255

241256
format.json do

docs/guide/routing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ end
3434

3535
Some server-side frameworks allow you to generate URLs from named routes. However, you will not have access to those helpers client-side. Here are a couple ways to still use named routes with Inertia.
3636

37-
The first option is to generate URLs server-side and include them as props. Notice in this example how we're passing the `edit_url` and `create_url` to the `Users/Index` component.
37+
The first option is to generate URLs server-side and include them as props. Notice in this example how we're passing the `edit_url` and `create_url` to the `users/index` component.
3838

3939
```ruby
4040
class UsersController < ApplicationController
4141
def index
42-
render inertia: 'Users/Index', props: {
42+
render inertia: {
4343
users: User.all.map do |user|
4444
user.as_json(
4545
only: [ :id, :name, :email ]

docs/guide/server-side-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class EventsController < ApplicationController
174174
def show
175175
event = Event.find(params[:id])
176176
177-
render inertia: 'Event/Show', props: {
177+
render inertia: {
178178
event: event.as_json(
179179
only: [:id, :title, :start_date, :description]
180180
)

0 commit comments

Comments
 (0)