Skip to content

Commit d25c7b4

Browse files
author
Robert Mosolgo
committed
Merge pull request #348 from garbles/controller-rendering-readme
Add documentation for controller component rendering
2 parents ae930e9 + 6d4e722 commit d25c7b4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,22 @@ end
204204
- On MRI, you'll get a deadlock with `pool_size` > 1
205205
- If you're using JRuby, you can increase `pool_size` to have real multi-threaded rendering.
206206

207+
### Rendering components instead of views
208+
209+
Components can also be prerendered directly from a controller action with the custom `component` renderer. For example:
210+
211+
```ruby
212+
class TodoController < ApplicationController
213+
def index
214+
@todos = Todo.all
215+
render component: 'TodoList', props: { todos: @todos }, tag: 'span'
216+
end
217+
end
218+
```
219+
220+
This custom renderer behaves the same as a normal view renderer and accepts the usual arguments - `content_type`, `layout`, `location` and `status`.
221+
By default, your current layout will be used and the component, rather than a view, will be rendered in place of `yield`.
222+
207223
### Component generator
208224

209225
`react-rails` ships with a Rails generator to help you get started with a simple component scaffold.

0 commit comments

Comments
 (0)