Changeset 927
- Timestamp:
- 03/20/05 14:04:33 (4 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/routing.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/routing_tests.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r911 r927 1 1 *SVN* 2 3 * Added path collection syntax for Routes that will gobble up the rest of the url and pass it on to the controller #830 [rayners]. Example: 4 5 map.connect 'categories/*path_info', :controller => 'categories', :action => 'show' 6 7 A request for /categories/top-level-cat, would give @params[:path_info] with "top-level-cat". 8 A request for /categories/top-level-cat/level-1-cat, would give @params['path_info'] with "top-level-cat/level-1-cat" and so forth. 2 9 3 10 * Fixed options_for_select on selected line issue #624 [Florian Weber] trunk/actionpack/lib/action_controller/routing.rb
r870 r927 49 49 components = @items.collect do |item| 50 50 if item.kind_of? Symbol 51 collection = false 52 53 if /^\*/ =~ item.to_s 54 collection = true 55 item = item.to_s.sub(/^\*/,"").intern 56 end 57 51 58 used_names[item] = true 52 59 value = options[item] || defaults[item] || @defaults[item] 53 60 return nil, requirements_for(item) unless passes_requirements?(item, value) 61 54 62 defaults = {} unless defaults == {} || value == defaults[item] # Stop using defaults if this component isn't the same as the default. 55 (value.nil? || item == :controller) ? value : CGI.escape(value.to_s) 56 else item 63 64 if value.nil? || item == :controller 65 value 66 elsif collection 67 CGI.escape(value.to_s).gsub(/%2F/, "/") 68 else 69 CGI.escape(value.to_s) 70 end 71 else 72 item 57 73 end 58 74 end … … 97 113 options[:controller] = controller_class.controller_path 98 114 return nil, requirements_for(:controller) unless passes_requirements?(:controller, options[:controller]) 115 elsif /^\*/ =~ item.to_s 116 value = components.join("/") || @defaults[item] 117 components = [] 118 options[item.to_s.sub(/^\*/,"").intern] = value.nil? ? value : CGI.unescape(value) 99 119 elsif item.kind_of? Symbol 100 120 value = components.shift || @defaults[item] … … 143 163 144 164 def items=(path) 145 items = path.split('/').collect {|c| (/^ :(\w+)$/ =~ c) ? $1.intern: c} if path.kind_of?(String) # split and convert ':xyz' to symbols165 items = path.split('/').collect {|c| (/^(:|\*)(\w+)$/ =~ c) ? (($1 == ':' ) ? $2.intern : "*#{$2}".intern) : c} if path.kind_of?(String) # split and convert ':xyz' to symbols 146 166 items.shift if items.first == "" 147 167 items.pop if items.last == "" … … 173 193 end 174 194 def requirements_for(name) 195 name = name.to_s.sub(/^\*/,"").intern if (/^\*/ =~ name.inspect) 175 196 presence = (@defaults.key?(name) && @defaults[name].nil?) 176 197 requirement = case @requirements[name] trunk/actionpack/test/controller/routing_tests.rb
r855 r927 326 326 assert_equal %w{action id}, leftovers 327 327 end 328 329 def test_path_collection 330 route '*path_info', :controller => 'content', :action => 'fish' 331 verify_recognize'path/with/slashes', 332 :controller => 'content', :action => 'fish', :path_info => 'path/with/slashes' 333 verify_generate('path/with/slashes', {}, 334 {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'}, 335 {}) 336 end 328 337 329 338 def test_special_characters