Skip to content

Commit

Permalink
Add documentation on rendering ViewComponents outside of the view con…
Browse files Browse the repository at this point in the history
…text (#2065)

Closes #201
  • Loading branch information
joelhawksley authored Jul 31, 2024
1 parent ee24513 commit 4183f42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
8 changes: 8 additions & 0 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@chaadow

chaadow Aug 30, 2024

I followed this instruction but got private method view_context' called for an instance of ViewComponent::Base (NoMethodError)`

image
```

0 comments on commit 4183f42

Please sign in to comment.