Skip to content

Instantly share code, notes, and snippets.

@yuryroot
Created February 17, 2016 11:57
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Rails: using url helpers inside custom class.
module UrlHelpers
extend ActiveSupport::Concern
def default_url_options
Rails.configuration.action_mailer.default_url_options
end
included do
include Rails.application.routes.url_helpers
end
end
class MyClass
include UrlHelpers
end
MyClass.new.instance_eval { root_url }
=> "http://localhost:3000/"
MyClass.new.instance_eval { registration_url }
=> "http://localhost:3000/registration"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment