Skip to content

Commit 4183f42

Browse files
authored
Add documentation on rendering ViewComponents outside of the view context (#2065)
Closes #201
1 parent ee24513 commit 4183f42

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 5
1010

1111
## main
1212

13+
* Add documentation on rendering ViewComponents outside of the view context.
14+
15+
*Joel Hawksley*
16+
1317
* Look for preview files that end in `preview.rb` rather than `_preview.rb` to allow previews to exist in sidecar directory with test files.
1418

1519
*Seth Herr*

docs/guide/getting-started.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,11 @@ class PagesController < ApplicationController
120120
end
121121
end
122122
```
123+
124+
### Rendering ViewComponents outside of the view context
125+
126+
To render ViewComponents outside of the view context (such as in a background job, markdown processor, etc), instantiate a Rails controller:
127+
128+
```ruby
129+
ApplicationComponent.new.view_context.render(MyComponent.new)
130+
```

0 commit comments

Comments
 (0)