Raise error with tip when required ActionView context is missing
I'm new to Phlex and am submitting this PR to a gotcha that got me. The docs explain that you can render a component by calling call on it. Because I had decided to demo Phlex by migrating an existing ERB partial to a Phlex component, I needed to render my new Phlex component from another ERB view. I did this with call. (Had I been demoing Phlex by implementing a new view from scratch, I would have copied the docs more directly, which would have led me to use render.) But using call in this way raised the following error:
ActionView::Template::Error (undefined method `default_url_options' for nil):
... from ERB lines such as:
<%= Components::MyComponent.new.call.html_safe %>
Since my ERB and Phlex components made no direct reference to default_url_options, I ended up debugging for a while before realising that the ActionView context is set when you call render, so for components which include Rails helpers in this repo, you probably have to render them with render, not call. This PR shows a helpful error to other people who will make the same mistake:
👋 Please use `render` to render Components::MyComponent instances (instead
of my_component_instance.call). Using `render` allows the component to
receive the ActionView context, which is required by Phlex helpers it includes.
Let me know if you'd like me to change this PR in any way. Thanks for Phlex! Really excited about it.