Skip to content

Recommended way to call custom Rails helper methods #594

Answered by joeldrapper
adamlogic asked this question in Help
Discussion options

You must be logged in to vote

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:

module Helpers::AudioTag
  extend Phlex::Rails::HelperMacros
  define_output_helper :audio_tag
end

.define_output_helper_with_capture_block

This is for output helpers that accept a block, e.g. link_to("/"…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@adamlogic
Comment options

@joeldrapper
Comment options

Answer selected by joeldrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants