3 Comments
User's avatar
Sahu's avatar

Hi. Thanks for your content. I've started working with View Components, and your information has helped me a lot.

I tried using the component helper you shared in your talks:

```

def component(name, *args, **kwargs, &block)

render("#{name}_component".classify.constantize.new(*args, **kwargs), &block)

end

```

But it gave me problems when I nest a VC into another. I found a solution I wanted to share with you because you greatly helped me:

```

def component(name, *args, **kwargs, &block)

"#{name}_component".classify.constantize.new(*args, **kwargs).render_in(self, &block)

end

```

This solution uses the view_context (self) to render the component

Thank you again.

Expand full comment
Radoslav Stankov's avatar

Thanks for sharing 🙌

Expand full comment
Sahu's avatar

I made one for "with_collection" too

```

def component_with_collection(name, *args, **kwargs, &block)

"#{name}_component".classify.constantize.with_collection(*args, **kwargs).render_in(self, &block)

end

```

Expand full comment