Recommended way to call custom Rails helper methods #594
-
When migrating a legacy app to Phlex, we have many existing helper methods that return HTML. I can call these methods via def template
div class: "relative px-4" do
unsafe_raw helpers.svg_icon(:chevronleft)
end
end |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That’s a really good question. It’s not been considered part of the public API, but there's actually a module to help define adapters for Rails helpers, which is used in defining all the built-in adapters. The built-in adapters are mostly all defined in this file, which is a good example to look at. The module is
|
Beta Was this translation helpful? Give feedback.
That’s a really good question. It’s not been considered part of the public API, but there's actually a module to help define adapters for Rails helpers, which is used in defining all the built-in adapters. The built-in adapters are mostly all defined in this file, which is a good example to look at.
The module is
Phlex::Rails::HelperMacros
, and it provides the following:.define_output_helper
This is for helpers that return HTML. You’d typically use them with
<%= %>
tags in ERB.Example:
.define_output_helper_with_capture_block
This is for output helpers that accept a block, e.g.
link_to("/"…