Class: CGI

Inherits:
Object show all
Defined in:
lib/vex/base/cgi_ext.rb

Defined Under Namespace

Modules: Etest

Class Method Summary collapse

Class Method Details

.url_for(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vex/base/cgi_ext.rb', line 4

def self.url_for(*args)
  opts = case args.last
  when Array, Hash then args.pop
  else                  {}
  end
  
  url_base = args.map do |arg|
    arg.gsub(/(^\/)|(\/$)/, "")
  end.join("/")
  
  return url_base if opts.empty?

  url_base += url_base.index("?") ? "&" : "?"

  url_base + opts.map do |k,v|
    p = escape(k.to_s)
    p += "=" + escape(v.to_s) if v
    p
  end.join("&")
end