Replies: 2 comments 2 replies
-
Good question. We should definitely explain this in the documentation. The a(href: helpers.url_for(@post)) { "View post" } However, it falls apart when you try to use a tag helper such as helpers.link_to(@post) { "View post" } This will not do anything because the unsafe_raw helpers.link_to(@post) { "View post" } It’s not nice to have to use The adapter in def link_to(...)
output = helpers.link_to(...)
unsafe_raw(output) if output.is_a?(ActiveSupport::SafeBuffer)
end Additionally, Rails provides helpers such as <%= form_with(@post) do |f| %>
<div class="field">
<%= f.text_field :title %>
</div>
<% end %> To do the same in Phlex, ideally you’d want to use this: form_with(@post) do |f|
div class: "field" do
f.text_field :title
end
end To make this work, not only do we need The All the adapters are designed to adapt the underlying helpers to work naturally in Phlex. They’re opt-in because I expect many of them will not be used in a Phlex context. The The idea is that you can include the helpers as and when you need them. And if you use specific helpers a lot, you can include them in your |
Beta Was this translation helpful? Give feedback.
-
@joeldrapper is there a way to include all those helpers at once, instead of one-by-one? Because of, you know, convention-over-configuration & stuff ;) |
Beta Was this translation helpful? Give feedback.
-
I'm a little unsure why I should use the helper modules instead of calling helpers on the
helpers
object. Obviously including a module avoids the need to callhelpers.my_helper
everywhere, but is there any other benefit?Beta Was this translation helpful? Give feedback.
All reactions