-
Notifications
You must be signed in to change notification settings - Fork 468
Closed
Description
Feature request
Allow refactoring small view parts into a separate view, and be able to render
them into the template. These views should not be available outside the component.
app/components/my_component/my_component.html.erb
app/components/my_component/a_part.html.erb
<%# my_component.html.erb %>
<%= render 'a_part' %>
Motivation
Sometimes it is useful to separate a sub-component from the component. For example, if I want to render a popover with extra info about a particular model, I would want to extract that popover into a separate view.
Alternative Solutions:
- Extract a new component. Because the popover is not a generic one to be used in other parts of the application, it doesn't make much sense to create a (now public) component for it.
- Use
content_for
. This is not suitable if the partial needs to take arguments. In my example, it wouldn't work if I'm displaying a list of models and I want to show the popover for each model.
Prior art:
ActionView does support partials, of course.
Cells does allow multiple views per cell, and allows using render view: 'a_part'
.
Possible solutions I see
- Provide a method that prefixes the component dir and then goes on to call
render template:
with the full path. I would suspect this is relatively slow given thatrender
is slow in ActionView. - Precompile all the templates into methods with a reserved prefix, and allow calling them from the view. For example, using
extra_views_{view_name}
.
MatheusRich, delynn, 007lva, jmadkins, RolandStuder and 12 more
Metadata
Metadata
Assignees
Labels
No labels