Replies: 1 comment
-
I've been experimenting with this idea, ViewComponents as views. I've only translated one view and created a few generic components that was needed by this view. I already love the idea. Without even thinking I applied regular patterns and abstractions that one would normally use with plain old Ruby objects. Doing this with regular views would require decorators/view models/helpers or similar. With ViewComponents it happened naturally. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been toying with the idea of using ViewComponents as views - that is, rendering components from the controller. I want to set this as a standard so that the view layer can be tested more easily and is better encapsulated. In this sense, a ViewComponent would be a view model and a view packed into one. ViewComponents can already be rendered from the controller, but so far I believe you have to manually specify the component to render. Perhaps the gem could add to the lookup context and accept ViewComponents as render targets?
The key word here is add to the view context - completely fresh apps can start with ViewComponent driving their views from the outset, but for those of us using ViewComponent in existing apps, migrating away from using view templates could potentially take some time.
Something to ease migration from view templates to ViewComponents would be helpful too. If we were to make some kind of automation for it, it would need to be careful of helpers, and potentially also expose instance variables on the component if the template used them. I'm not sure how much of this migration process could be done manually.
This part's more specific to my use case, but I think my implementation will be to have these under
app/views
, most likely namespaced underView
orViews
too. Might need to do some Zeitwerk jiggery-pokery if so, but I don't expect that to be the responsibility ofview_component
.Beta Was this translation helpful? Give feedback.
All reactions