diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6723f4b29..f31df066f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 5 ## main +* Add documentation on rendering ViewComponents outside of the view context. + + *Joel Hawksley* + * Look for preview files that end in `preview.rb` rather than `_preview.rb` to allow previews to exist in sidecar directory with test files. *Seth Herr* diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index 8470f6dab..1049ef6b5 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -120,3 +120,11 @@ class PagesController < ApplicationController end end ``` + +### Rendering ViewComponents outside of the view context + +To render ViewComponents outside of the view context (such as in a background job, markdown processor, etc), instantiate a Rails controller: + +```ruby +ApplicationComponent.new.view_context.render(MyComponent.new) +```