Class: ActionController::Routing::RouteSet::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/extensions/action_controller/routing/route_set.rb

Instance Method Summary collapse

Instance Method Details

#connect_rtml(options = {}) ⇒ Object

Modifies your route set to produce TML-compatible routes. Also connects the default TML request (/index.tml) to the options you provide, if any.

Unlike the rest of Rails routing, if you call #connect_rtml multiple times with different options, the /index.tml path will be updated to reflect the new options.

To use, just add the following to your /config/routes.rb file: map.connect_rtml :controller => “start_page”



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/extensions/action_controller/routing/route_set.rb', line 14

def connect_rtml(options = {})
  make_rtml_connection('/:controller/:action.:format', '/rtml/index.rtml')
  make_rtml_connection('/:controller/:action.:id.:format', '/rtml/index.1.rtml')
  make_rtml_connection('/:controller/:action/:id', '/rtml/index/1')

  connect_options = !options.empty?
  ActionController::Routing::Routes.routes.each do |route|
    segs = route.segments.to_s[0...-1]
    if segs =~ /^\/index.tml(\/|)$/ && connect_options
      route.requirements.merge! options.reverse_merge(:format => 'rtml')
      connect_options = false
    end
  end

  if connect_options
    connect '/index.tml', options.reverse_merge(:format => 'rtml') unless options.empty?
  end
end