Skip to content

Instantly share code, notes, and snippets.

@yuryroot
Created February 17, 2016 11:57
Show Gist options
  • Save yuryroot/aab1695a33bc9236cc8d to your computer and use it in GitHub Desktop.
Save yuryroot/aab1695a33bc9236cc8d to your computer and use it in GitHub Desktop.
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