Module: RubyMVC::LinkDispatcher

Included in:
AppController
Defined in:
lib/ruby_mvc/controllers/app_controller.rb

Overview

This module takes care of dispatching links to controller classes.

Instance Method Summary collapse

Instance Method Details

This method is a callback to allow links embedded in views to trigger controller actions in a loosely-coupled manner.

The default implementation will attempt to call methods based on applying the RubyMVC#method_name transformation and checking if the controller responds to the method. To manually dispatch the method, simply override this method in the derived class.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_mvc/controllers/app_controller.rb', line 42

def link_activated(sender, link)
  puts "#link_activated(#{sender}, #{link})"
  uri = URI.parse(link)
  
  if uri.query
    params = CGI.parse(uri.query)
    params.each do |k, v|
      if v && v.size == 1
        params[k] = v.first
      end
    end
  end

  m = RubyMVC.method_name(uri.path).to_sym
  if self.respond_to? m
    self.send(m, sender, link, params)
  end
end