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"

Note that you should do this for each RTML controller in your application. To prevent overriding the /index.tml page, pass :no_index => true:

map.connect_rtml :controller => "another_page", :no_index => true


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/extensions/action_controller/routing/route_set.rb', line 18

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

  unless options.empty? || no_index
    connect '/index.tml', options.reverse_merge(:format => 'rtml')
  end
  
  if options[:controller]
    controller = options[:controller]
    make_rtml_connection("/#{controller}/:action.:format",     "/#{controller}/index.rtml",   :controller => controller)
    make_rtml_connection("/#{controller}/:action.:id.:format", "/#{controller}/index.1.rtml", :controller => controller)
  end
end