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%.

Methods

Public Class methods

[Source]

     # 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

Public Instance methods

[Source]

     # 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

[Source]

     # 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 (.)

[Source]

     # 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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/routing/segments.rb, line 320
320:       def regexp_chunk
321:         '/|(\.[^/?\.]+)?'
322:       end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/routing/segments.rb, line 324
324:       def to_s
325:         '(.:format)?'
326:       end

[Validate]