Module: UzuUzu::Helper::Route

Defined in:
lib/uzuuzu-core/helper/route.rb

Instance Method Summary collapse

Instance Method Details

#root_uriObject



46
47
48
49
50
51
52
53
54
# File 'lib/uzuuzu-core/helper/route.rb', line 46

def root_uri
  abs_uri = "#{request.scheme}://#{request.host}"
  if request.scheme == 'https' && request.port != 443 ||
  request.scheme == 'http' && request.port != 80
    abs_uri << ":#{request.port}"
  end
  abs_uri << "#{request.env['SCRIPT_NAME']}"
  abs_uri
end

#url_for(*args) ⇒ Object Also known as: r



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/uzuuzu-core/helper/route.rb', line 29

def url_for(*args)
  route_string = route.clone
  if /index$/ =~ route_string 
    route_string = route_string.split('/')[0...-1].join('/')
  end
  if args[-1].kind_of?(Hash)
    query = query_string(args.pop)
  end
  args.each do |arg|
    route_string << "/#{arg}"
  end
  route_string << '/' if args.blank?
  route_string << query unless query.blank?
  route_string
end

#url_for_controller(controller, *args) ⇒ Object Also known as: rf



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/uzuuzu-core/helper/route.rb', line 6

def url_for_controller(controller, *args)
  route_string = request.env['SCRIPT_NAME'].clone
  application.controllers.each do |root_controller|
    re = Regexp.compile("^#{root_controller.name}::")
    if re =~ controller.name
      path = controller.name.gsub(re, '').gsub(/Controller$/, '').to_const_path
      route_string << "/#{path}" unless path == 'index'
      break
    end
  end
  if args[-1].kind_of?(Hash)
    query = query_string(args.pop)
  end
  args.each do |arg|
    route_string << "/#{arg}"
  end
  
  route_string << '/' if args.blank?
  route_string << query unless query.blank?
  route_string
end