Flowdock
method

default_controller_and_action

Importance_0
v4.1.8 - Show latest stable - 0 notes - Class: ActionDispatch::Routing::Mapper::Mapping
default_controller_and_action() private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 208
          def default_controller_and_action
            if to.respond_to?(:call)
              { }
            else
              if to.is_a?(String)
                controller, action = to.split('#')
              elsif to.is_a?(Symbol)
                action = to.to_s
              end

              controller ||= default_controller
              action     ||= default_action

              if @scope[:module] && !controller.is_a?(Regexp)
                if controller =~ %{\A/}
                  controller = controller[1..-1]
                else
                  controller = [@scope[:module], controller].compact.join("/").presence
                end
              end

              if controller.is_a?(String) && controller =~ %{\A/}
                raise ArgumentError, "controller name should not start with a slash"
              end

              controller = controller.to_s unless controller.is_a?(Regexp)
              action     = action.to_s     unless action.is_a?(Regexp)

              if controller.blank? && segment_keys.exclude?(:controller)
                message = "Missing :controller key on routes definition, please check your routes."
                raise ArgumentError, message
              end

              if action.blank? && segment_keys.exclude?(:action)
                message = "Missing :action key on routes definition, please check your routes."
                raise ArgumentError, message
              end

              if controller.is_a?(String) && controller !~ /\A[a-z_0-9\/]*\z/
                message = "'#{controller}' is not a supported controller name. This can lead to potential routing problems."
                message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
                raise ArgumentError, message
              end

              hash = {}
              hash[:controller] = controller unless controller.blank?
              hash[:action]     = action unless action.blank?
              hash
            end
          end
Register or log in to add new notes.