public Method

RouteBuilder.build(path, options)

Construct and return a route with the given path and options.

Source Code

# File action_controller/routing/builder.rb, line 160
def build(path, options)
  # Wrap the path with slashes
  path = "/#{path}" unless path[0] == ?/
  path = "#{path}/" unless path[-1] == ?/

  path = "/#{options[:path_prefix].to_s.gsub(/^\//,'')}#{path}" if options[:path_prefix]

  segments = segments_for_route_path(path)
  defaults, requirements, conditions = divide_route_options(segments, options)
  requirements = assign_route_options(segments, defaults, requirements)

  route = Route.new

  route.segments = segments
  route.requirements = requirements
  route.conditions = conditions

  if !route.significant_keys.include?(:action) && !route.requirements[:action]
    route.requirements[:action] = "index"
    route.significant_keys << :action
  end

  # Routes cannot use the current string interpolation method
  # if there are user-supplied :requirements as the interpolation
  # code won't raise RoutingErrors when generating
  if options.key?(:requirements) || route.requirements.keys.to_set != Routing::ALLOWED_REQUIREMENTS_FOR_OPTIMISATION
    route.optimise = false
  end

  if !route.significant_keys.include?(:controller)
    raise ArgumentError, "Illegal route: the :controller must be specified!"
  end

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