How to access URL helper from rails module

前端 未结 5 950
感情败类
感情败类 2020-12-25 10:42

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

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


        
5条回答
  •  心在旅途
    2020-12-25 11:22

    Delegation to url_helpers seems much better than including the whole module into your model

    delegate :url_helpers, to: 'Rails.application.routes' 
    url_helpers.users_url  => 'www.foo.com/users'
    

    reference

提交回复
热议问题