Class | ActionController::Routing::OptionalFormatSegment |
In: |
vendor/rails/actionpack/lib/action_controller/routing/segments.rb
|
Parent: | DynamicSegment |
The OptionalFormatSegment allows for any resource route to have an optional :format, which decreases the amount of routes created by 50%.
# File vendor/rails/actionpack/lib/action_controller/routing/segments.rb, line 312 312: def initialize(key = nil, options = {}) 313: super(:format, {:optional => true}.merge(options)) 314: end
# File vendor/rails/actionpack/lib/action_controller/routing/segments.rb, line 328 328: def extract_value 329: "#{local_name} = options[:#{key}] && options[:#{key}].to_s.downcase" 330: end
# File vendor/rails/actionpack/lib/action_controller/routing/segments.rb, line 316 316: def interpolation_chunk 317: "." + super 318: end
the value should not include the period (.)
# File vendor/rails/actionpack/lib/action_controller/routing/segments.rb, line 333 333: def match_extraction(next_capture) 334: %[ 335: if (m = match[#{next_capture}]) 336: params[:#{key}] = URI.unescape(m.from(1)) 337: end 338: ] 339: end