Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6082

Show
Ignore:
Timestamp:
01/28/07 17:29:51 (2 years ago)
Author:
ulysses
Message:

Allow Routes to generate all urls for a set of options by specifying :generate_all => true. References #1739.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6081 r6082  
    11*SVN* 
     2 
     3* Allow Routes to generate all urls for a set of options by specifying :generate_all => true. Allows caching to properly set or expire all paths for a resource. References #1739. [Nicholas Seckar] 
    24 
    35* Change the query parser to map empty GET params to "" rather than nil. Closes #5694. [Nicholas Seckar] 
  • trunk/actionpack/lib/action_controller/routing.rb

    r6071 r6082  
    12151215      def generate(options, recall = {}, method=:generate) 
    12161216        named_route_name = options.delete(:use_route) 
     1217        generate_all = options.delete(:generate_all) 
    12171218        if named_route_name 
    12181219          named_route = named_routes[named_route_name] 
     
    12501251 
    12511252          raise RoutingError, "Need controller and action!" unless controller && action 
     1253           
     1254          if generate_all 
     1255            # Used by caching to expire all paths for a resource 
     1256            return routes.collect do |route| 
     1257              route.send(method, options, merged, expire_on) 
     1258            end.compact 
     1259          end 
     1260           
    12521261          # don't use the recalled keys when determining which routes to check 
    12531262          routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }] 
  • trunk/actionpack/test/controller/routing_test.rb

    r6057 r6082  
    17201720  end 
    17211721   
     1722  def test_generate_all 
     1723    set.draw do |map| 
     1724      map.connect 'show_post/:id', :controller => 'post', :action => 'show' 
     1725      map.connect ':controller/:action/:id' 
     1726    end 
     1727    all = set.generate( 
     1728      {:action => 'show', :id => 10, :generate_all => true}, 
     1729      {:controller => 'post', :action => 'show'} 
     1730    ) 
     1731    assert_equal 2, all.length 
     1732    assert_equal '/show_post/10', all.first 
     1733    assert_equal '/post/show/10', all.last 
     1734  end 
     1735   
    17221736end 
    17231737