Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rails Components From Scratch Discussion

Great episode Chris!

Reply

Super episode -- putting this to work right now.

Reply

Thanks Chris - loved the episode: very informative. Lovely dynamic refactoring work, too, imho

Reply

The refactoring part is half the fun. πŸ˜„

Reply

Thank you very much, Chris - I really enjoyed that episode

Reply

Glad you found it helpful!

Reply

Great episode Chris, super cool explanation how it works behind the scenes!

Reply

These are my favorite kinds of things to learn and teach. Learning behind the scenes really helps you become a better developer. πŸ’ͺ

Reply

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.

Reply

I guess you could write a view spec and do this:

render Button.new(to: "some-path")
expect(rendered).to include("href=\"some-path\"")

Reply

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. πŸ‘

Reply

Great. That was a really useful video, thanks Chris!

Reply

Didn't know about the ... nor the !!@variable very nice 🀯

Reply

Cool epicode, let me think why I need gem ViewComponent, lol. Thanks, Chris.

Reply

With gem ViewComponent, how to make component render partial in it's self directory as action view?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.