Module: Rad::Router::CoreRoutingHelper

Defined in:
lib/rad/router/_core_routing_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (protected)



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rad/router/_core_routing_helper.rb', line 28

def method_missing m, *args, &block
  m = m.to_s
  if m =~ /path$/
    params = parse_routing_arguments(*args)
    klass, method = router.encode_method m, params.include?(:id)

    url_for klass, method, params
  else
    super m.to_sym, *args, &block
  end
end

Instance Method Details

#default_path(options = {}) ⇒ Object



6
7
8
# File 'lib/rad/router/_core_routing_helper.rb', line 6

def default_path options = {}
  url_for_path rad.router.default_path, options.merge(url_root: false)
end

#parse_routing_arguments(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/rad/router/_core_routing_helper.rb', line 17

def parse_routing_arguments *args
  params = args.extract_options!
  raise "invalid usage!" unless args.size <= 1
  if args.size == 1
    raise "duplicate :id pameter!" if params.include?(:id) or params.include?('id')
    params[:id] = args.first.to_param
  end
  params
end

#return_to_path(options = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/rad/router/_core_routing_helper.rb', line 10

def return_to_path options = {}
  dont_persist_params do
    path = params[:_return_to] || workspace.request.session['return_to'] || rad.router.default_path
    url_for_path path, options.merge(url_root: false)
  end
end