1
votes

How would I go about using helper methods from a config file?

This may be unorthodox but it makes sense in the context that I need it. The helper method I need is used to properly format URLs in one of my views. The config file is the initializer for the sitemap_generator Gem, where I need the helper method to format some of the URLs.

I tried require, which does indeed include the module, but get undefined method for module when I call it.

2

2 Answers

1
votes

This is how you include your helper in the SitemapGenerator config :

SitemapGenerator::Interpreter.send :include, ApplicationHelper

0
votes

Does your method need to be in a helper? Can't you put it in a class in your lib folder?

# lib/my_url_helper.rb
class MyUrlHelper
  def self.proper_format(...)
    ...
  end
end

# app/helpers/application_helper.rb
def proper_format(*args)
  MyUrlHelper.proper_format(*args)
end

Tip / personal experience: Most of the time you do something "unorthodox" you are trying to solve the wrong problem.