class method self.controller_relative_to

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

self.controller_relative_to(controller, previous)

Returns a controller path for a new controller based on a previous controller path. Handles 4 scenarios:

  • stay in the previous controller:

    controller_relative_to( nil, "groups/discussion" ) # => "groups/discussion"
    
  • stay in the previous namespace:

    controller_relative_to( "posts", "groups/discussion" ) # => "groups/posts"
    
  • forced move to the root namespace:

    controller_relative_to( "/posts", "groups/discussion" ) # => "posts"
    
  • previous namespace is root:

    controller_relative_to( "posts", "anything_with_no_slashes" ) # =>"posts"
    

Parameters

controller req
previous req
Source
# File actionpack/lib/action_controller/routing.rb, line 363
      def controller_relative_to(controller, previous)
        if controller.nil?           then previous
        elsif controller[0] == ?/    then controller[1..-1]
        elsif %r{^(.*)/} =~ previous then "#{$1}/#{controller}"
        else controller
        end
      end

Defined in actionpack/lib/action_controller/routing.rb line 363 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::Routing

Type at least 2 characters to search.

↑↓ navigate · open · esc close