Skip to Content Skip to Search

module ActionDispatch::Routing::Mapper::HttpHelpers

Public instance methods

Define a route that recognizes HTTP CONNECT (and GET) requests. More specifically this recognizes HTTP/1 protocol upgrade requests and HTTP/2 CONNECT requests with the protocol pseudo header. For supported arguments, see match

connect 'live', to: 'live#index'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 889
def connect(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: false, format: false, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :connect) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :connect)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :connect)
    action ||= assign_deprecated_option(deprecated_options, :action, :connect)
    on ||= assign_deprecated_option(deprecated_options, :on, :connect)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :connect)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :connect)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :connect) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :connect) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :connect)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :connect)
    assign_deprecated_options(deprecated_options, mapping, :connect)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: [:get, :connect], &block)
  self
end

Define a route that only recognizes HTTP DELETE. For supported arguments, see match

delete 'broccoli', to: 'food#broccoli'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 839
def delete(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :delete) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :delete)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :delete)
    action ||= assign_deprecated_option(deprecated_options, :action, :delete)
    on ||= assign_deprecated_option(deprecated_options, :on, :delete)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :delete)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :delete)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :delete) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :delete) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :delete)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :delete)
    assign_deprecated_options(deprecated_options, mapping, :delete)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: :delete, &block)
  self
end

Define a route that only recognizes HTTP GET. For supported arguments, see match

get 'bacon', to: 'food#bacon'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 743
def get(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :get) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :get)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :get)
    action ||= assign_deprecated_option(deprecated_options, :action, :get)
    on ||= assign_deprecated_option(deprecated_options, :on, :get)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :get)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :get)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :get) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :get) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :get)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :get)
    assign_deprecated_options(deprecated_options, mapping, :get)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: :get, &block)
  self
end

Define a route that only recognizes HTTP OPTIONS. For supported arguments, see match

options 'carrots', to: 'food#carrots'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 863
def options(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: false, format: false, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :options) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :options)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :options)
    action ||= assign_deprecated_option(deprecated_options, :action, :options)
    on ||= assign_deprecated_option(deprecated_options, :on, :options)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :options)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :options)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :options) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :options) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :options)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :options)
    assign_deprecated_options(deprecated_options, mapping, :options)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: :options, &block)
  self
end

Define a route that only recognizes HTTP PATCH. For supported arguments, see match

patch 'bacon', to: 'food#bacon'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 791
def patch(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :patch) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :patch)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :patch)
    action ||= assign_deprecated_option(deprecated_options, :action, :patch)
    on ||= assign_deprecated_option(deprecated_options, :on, :patch)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :patch)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :patch)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :patch) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :patch) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :patch)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :patch)
    assign_deprecated_options(deprecated_options, mapping, :patch)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: :patch, &block)
  self
end

Define a route that only recognizes HTTP POST. For supported arguments, see match

post 'bacon', to: 'food#bacon'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 767
def post(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :post) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :post)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :post)
    action ||= assign_deprecated_option(deprecated_options, :action, :post)
    on ||= assign_deprecated_option(deprecated_options, :on, :post)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :post)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :post)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :post) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :post) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :post)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :post)
    assign_deprecated_options(deprecated_options, mapping, :post)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: :post, &block)
  self
end

Define a route that only recognizes HTTP PUT. For supported arguments, see match

put 'bacon', to: 'food#bacon'
Source code GitHub
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 815
def put(*path_or_actions, as: DEFAULT, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)
  if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
    as = assign_deprecated_option(deprecated_options, :as, :put) if deprecated_options.key?(:as)
    to ||= assign_deprecated_option(deprecated_options, :to, :put)
    controller ||= assign_deprecated_option(deprecated_options, :controller, :put)
    action ||= assign_deprecated_option(deprecated_options, :action, :put)
    on ||= assign_deprecated_option(deprecated_options, :on, :put)
    defaults ||= assign_deprecated_option(deprecated_options, :defaults, :put)
    constraints ||= assign_deprecated_option(deprecated_options, :constraints, :put)
    anchor = assign_deprecated_option(deprecated_options, :anchor, :put) if deprecated_options.key?(:anchor)
    format = assign_deprecated_option(deprecated_options, :format, :put) if deprecated_options.key?(:format)
    path ||= assign_deprecated_option(deprecated_options, :path, :put)
    internal ||= assign_deprecated_option(deprecated_options, :internal, :put)
    assign_deprecated_options(deprecated_options, mapping, :put)
  end

  match(*path_or_actions, as:, to:, controller:, action:, on:, defaults:, constraints:, anchor:, format:, path:, internal:, **mapping, via: :put, &block)
  self
end

Definition files