Skip to content

Instantly share code, notes, and snippets.

@masarakki
Created January 21, 2015 10:45
Show Gist options
  • Save masarakki/6efe16fec2791db1ae10 to your computer and use it in GitHub Desktop.
Save masarakki/6efe16fec2791db1ae10 to your computer and use it in GitHub Desktop.
register_url
def self.register_url(name, url)
uri = URI.parse(url)
define_method("#{name}_url") do |options = {}|
anchor = options.delete(:anchor) if options
ActionDispatch::Http::URL.full_url_for(host: uri.host, scheme: uri.scheme, path: uri.path, anchor: anchor, params: options)
end
end
register_url :google, 'https://google.com/'
google_url(q: 'hello', anchor: 'foo')
#=> 'https://google.com/?q=hello#hoo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment