Phlex and ERB play nice together!

If you’re curious about Phlex but unsure of whether you want to go "all in", you can start small. You can render a Phlex component in ERB and you can yield back to the ERB template from Phlex. You can adopt Phlex gradually.

This code snippet displays an ERB template that renders a Phlex component called Users::NewsletterSubscriptions::Banner. The first render call yields to a block that in turns renders another ERB partial called "users/newsletter_subscriptions/form". These features help demonstrate Phlex’s compatibility with ERB.

app/views/users/newsletter_subscriptions/_banner.html.erb
<%= render Users::NewsletterSubscriptions::Banner.new do %>
  <%= render "users/newsletter_subscriptions/form" %>
<% end %>

Back to snippets