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
+48-16Lines changed: 48 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Superview
2
2
3
-
Build Rails applications, from the ground up, using [Phlex](https://www.phlex.fun/) components, like this.
3
+
Build Rails applications, from the ground up, using [Phlex](https://www.phlex.fun/)or [ViewComponent](https://viewcomponent.org/)components, like this.
4
4
5
5
```ruby
6
6
classPostsController < ApplicationController
@@ -17,6 +17,21 @@ class PostsController < ApplicationController
@@ -41,11 +56,16 @@ If bundler is not being used to manage dependencies, install the gem by executin
41
56
42
57
## Usage
43
58
44
-
Install `phlex-rails` in your Rails application.
59
+
Add `include Superview::Actions` to any controllers you'd like to render components as controller actions.
45
60
46
-
$ bin/rails generate phlex:install
61
+
```ruby
62
+
classPostsController < ApplicationController
63
+
includeSuperview::Actions
64
+
# Your code...
65
+
end
66
+
```
47
67
48
-
Then add `include Superview::Actions`to any controllers you'd like to render Phlex components.
68
+
Then add classes to your controller that map to the actions you'd like to render. The `Show` class will render when the `PostsController#show` action is called and the `Edit` class will render when the `PostsController#edit` action is called.
49
69
50
70
```ruby
51
71
classPostsController < ApplicationController
@@ -62,20 +82,37 @@ class PostsController < ApplicationController
The `Show` class will render when the `PostsController#show` action is called. To use along side other formats or render manually, you can define the `PostsController#show` as you'd expect:
107
+
### Explicit rendering
108
+
109
+
You can explicitly render a component in a controller action method. In this example, we needed to render a the `Show` component in the `html` format and a JSON response in the `json` format.
73
110
74
111
```ruby
75
112
classPostsController < ApplicationController
76
113
includeSuperview::Actions
77
114
78
-
before_action :load_post
115
+
# Your code...
79
116
80
117
classShow < ApplicationComponent
81
118
attr_accessor:post
@@ -88,8 +125,10 @@ class PostsController < ApplicationController
0 commit comments