public Method

RouteBuilder.ensure_required_segments(segments)

Makes sure that there are no optional segments that precede a required segment. If any are found that precede a required segment, they are made required.

Source Code

# File action_controller/routing/builder.rb, line 143
def ensure_required_segments(segments)
  allow_optional = true
  segments.reverse_each do |segment|
    allow_optional &&= segment.optional?
    if !allow_optional && segment.optional?
      unless segment.optionality_implied?
        warn "Route segment \"#{segment.to_s}\" cannot be optional because it precedes a required segment. This segment will be required."
      end
      segment.is_optional = false
    elsif allow_optional && segment.respond_to?(:default) && segment.default
      # if a segment has a default, then it is optional
      segment.is_optional = true
    end
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.