Rails Components From Scratch Discussion
Thanks Chris - loved the episode: very informative. Lovely dynamic refactoring work, too, imho
The refactoring part is half the fun. π
Thank you very much, Chris - I really enjoyed that episode
Glad you found it helpful!
Great episode Chris, super cool explanation how it works behind the scenes!
These are my favorite kinds of things to learn and teach. Learning behind the scenes really helps you become a better developer. πͺ
This is great! I wonder how easy it would be to get unit tests setup to do this kind of thing:
button = Components::Button.new(text: "Click me")
result = button.render_in(view_context)
expect(result).to include("Click me")
Using RSpec, I could imagine creating "component" type tests where the view_context
is available in them. I don't actually know how to make it available but i'd love to know how.
I guess you could write a view spec and do this:
render Button.new(to: "some-path")
expect(rendered).to include("href=\"some-path\"")
Yep, you would want to treat them as a view specs because that's what they are. view_context
is an instance of ActionView::Base. π
Great. That was a really useful video, thanks Chris!
Cool epicode, let me think why I need gem ViewComponent, lol. Thanks, Chris.
With gem ViewComponent, how to make component render partial in it's self directory as action view?