Skip to content

Commit fd0cfb5

Browse files
committed
bump version and improve readme
1 parent 24944ee commit fd0cfb5

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [3.0.0] - 2022-09-22
8+
9+
* Allow rails layout to set inertia layout. Thanks @ElMassimo!
10+
* Add the ability to set inertia props and components via rails conventions (see readme)
11+
712
## [2.0.1] - 2022-07-12
813

914
* Fix for a middleware issue where global state could be polluted if an exception occurs in a request. Thanks @ElMassimo!

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ gem 'inertia_rails'
1414

1515
### Frontend
1616

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)
1818

1919
## Usage
2020

@@ -30,6 +30,53 @@ def index
3030
end
3131
```
3232

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+
class EventsController < ApplicationController
39+
use_inertia_instance_props
40+
41+
def index
42+
@events = Event.all
43+
end
44+
45+
end
46+
```
47+
48+
is the same as
49+
50+
51+
```ruby
52+
class EventsController < ApplicationController
53+
def index
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+
class EventsController < ApplicationController
75+
layout 'inertia_application'
76+
end
77+
```
78+
79+
3380
### Shared Data
3481

3582
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
54101
end
55102
```
56103

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.
107+
108+
```ruby
109+
inertia_share some_data: InertiaRails.lazy(lambda { some_very_slow_method })
110+
```
111+
57112
### Routing
58113

59114
If you don't need a controller to handle a static component, you can route directly to a component with the inertia route helper
@@ -62,6 +117,10 @@ If you don't need a controller to handle a static component, you can route direc
62117
inertia 'about' => 'AboutComponent'
63118
```
64119

120+
### SSR
121+
122+
Enable SSR via the config settings for `ssr_enabled` and `ssr_url`
123+
65124
## Configuration
66125

67126
Inertia Rails has a few different configuration options that can be set anywhere, but the most common location is from within an initializer.
@@ -72,6 +131,8 @@ InertiaRails.configure do |config|
72131

73132
# set the current version for automatic asset refreshing. A string value should be used if any.
74133
config.version = nil
134+
# enable default inertia rendering (warning! this will override rails default rendering behavior)
135+
config.default_render = true
75136

76137
# ssr specific options
77138
config.ssr_enabled = false

lib/inertia_rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module InertiaRails
2-
VERSION = "2.0.1"
2+
VERSION = "3.0.0"
33
end

0 commit comments

Comments
 (0)