You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+62-1Lines changed: 62 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ gem 'inertia_rails'
14
14
15
15
### Frontend
16
16
17
-
Rails 7 specific frontend docs coming soon. For now, check out the official Inertia docs at https://inertiajs.com/
17
+
Rails 7 specific frontend docs coming soon. For now, check out the official Inertia docs at https://inertiajs.com/ or see an example using React/Vite [here](https://github.com/BrandonShar/inertia-rails-template)
18
18
19
19
## Usage
20
20
@@ -30,6 +30,53 @@ def index
30
30
end
31
31
```
32
32
33
+
#### Rails Component and Instance Props
34
+
35
+
Starting in version 3.0, Inertia Rails allows you to provide your component name and props via common rails conventions.
36
+
37
+
```ruby
38
+
classEventsController < ApplicationController
39
+
use_inertia_instance_props
40
+
41
+
defindex
42
+
@events=Event.all
43
+
end
44
+
45
+
end
46
+
```
47
+
48
+
is the same as
49
+
50
+
51
+
```ruby
52
+
classEventsController < ApplicationController
53
+
defindex
54
+
render inertia:'events/index', props: {
55
+
events:Event.all
56
+
}
57
+
end
58
+
end
59
+
```
60
+
61
+
#### Instance Props and Default Render Notes
62
+
63
+
In order to use instance props, you must call `use_inertia_instance_props` on the controller (or a base controller it inherits from). If any props are provided manually, instance props
64
+
are automatically disabled for that response. Instance props are only included if they are defined after the before filter is set from `use_inertia_instance_props`.
65
+
66
+
Automatic component name is also opt in, you must set the `default_render` config value to `true`. Otherwise, you can simply `render inertia: true` for the same behavior explicitly.
67
+
68
+
### Layout
69
+
70
+
Inertia layouts use the rails layout convention and can be set or changed in the same way. The original `layout` config option is still functional, but will likely be deprecated in the future in favor
71
+
of using rails layouts.
72
+
73
+
```ruby
74
+
classEventsController < ApplicationController
75
+
layout 'inertia_application'
76
+
end
77
+
```
78
+
79
+
33
80
### Shared Data
34
81
35
82
If you have data that you want to be provided as a prop to every component (a common use-case is informationa about the authenticated user) you can use the `shared_data` controller method.
@@ -54,6 +101,14 @@ class EventsController < ApplicationController
54
101
end
55
102
```
56
103
104
+
### Lazy Props
105
+
106
+
On the front end, Inertia supports the concept of "partial reloads" where only the props requested are returned by the server. Sometimes, you may want to use this flow to avoid processing a particularly slow prop on the intial load. In this case, you can use Lazy props. Lazy props aren't evaluated unless they're specifically requested by name in a partial reload.
0 commit comments