How to access URL helper from rails module

sizzle picture sizzle · May 20, 2011 · Viewed 44.6k times · Source

I have a module with a function. It resides in /lib/contact.rb:

module Contact
  class << self
    def run(current_user)
      ...
    end
  end
end

I want to access the URL helpers like 'users_path' inside the module. How do I do that?

Answer

ronnieonrails picture ronnieonrails · May 20, 2011

In your module, just perform a :

 include Rails.application.routes.url_helpers