Flowdock
method

connect

Importance_0
v3.0.9 - Show latest stable - 0 notes - Class: ActionDispatch::Routing::DeprecatedMapper
connect(path, options = {}) public

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/deprecated_mapper.rb, line 39
      def connect(path, options = {})
        options = options.dup

        if conditions = options.delete(:conditions)
          conditions = conditions.dup
          method = [conditions.delete(:method)].flatten.compact
          method.map! { |m|
            m = m.to_s.upcase

            if m == "HEAD"
              raise ArgumentError, "HTTP method HEAD is invalid in route conditions. Rails processes HEAD requests the same as GETs, returning just the response headers"
            end

            unless HTTP_METHODS.include?(m.downcase.to_sym)
              raise ArgumentError, "Invalid HTTP method specified in route conditions"
            end

            m
          }

          if method.length > 1
            method = Regexp.union(*method)
          elsif method.length == 1
            method = method.first
          else
            method = nil
          end
        end

        path_prefix = options.delete(:path_prefix)
        name_prefix = options.delete(:name_prefix)
        namespace  = options.delete(:namespace)

        name = options.delete(:_name)
        name = "#{name_prefix}#{name}" if name_prefix

        requirements = options.delete(:requirements) || {}
        defaults = options.delete(:defaults) || {}
        options.each do |k, v|
          if v.is_a?(Regexp)
            if value = options.delete(k)
              requirements[k.to_sym] = value
            end
          else
            value = options.delete(k)
            defaults[k.to_sym] = value.is_a?(Symbol) ? value : value.to_param
          end
        end

        requirements.each do |_, requirement|
          if requirement.source =~ %{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
            raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
          end
          if requirement.multiline?
            raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
          end
        end

        requirements[:controller] ||= @set.controller_constraints

        if defaults[:controller]
          defaults[:action] ||= 'index'
          defaults[:controller] = defaults[:controller].to_s
          defaults[:controller] = "#{namespace}#{defaults[:controller]}" if namespace
        end

        if defaults[:action]
          defaults[:action] = defaults[:action].to_s
        end

        if path.is_a?(String)
          path = "#{path_prefix}/#{path}" if path_prefix
          path = path.gsub('.:format', '(.:format)')
          path = optionalize_trailing_dynamic_segments(path, requirements, defaults)
          glob = $1.to_sym if path =~ /\/\*(\w+)$/
          path = ::Rack::Mount::Utils.normalize_path(path)

          if glob && !defaults[glob].blank?
            raise ActionController::RoutingError, "paths cannot have non-empty default values"
          end
        end

        app = Routing::RouteSet::Dispatcher.new(:defaults => defaults, :glob => glob)

        conditions = {}
        conditions[:request_method] = method if method
        conditions[:path_info] = path if path

        @set.add_route(app, conditions, requirements, defaults, name)
      end
Register or log in to add new notes.