HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/default/doc/actionpack-6.1.4.1/ri/ActionDispatch/Routing/cdesc-Routing.ri
U:RDoc::NormalModule[iI"Routing:ETI"ActionDispatch::Routing;T0o:RDoc::Markup::Document:@parts[o;;[xo:RDoc::Markup::Paragraph;[	I"MThe routing module provides URL rewriting in native Ruby. It's a way to ;TI"Jredirect incoming requests to controllers and actions. This replaces ;TI"Pmod_rewrite rules. Best of all, Rails' \Routing works with any web server. ;TI"5Routes are defined in <tt>config/routes.rb</tt>.;To:RDoc::Markup::BlankLineo;	;[I"PThink of creating routes as drawing a map for your requests. The map tells ;TI"7them where to go based on some predefined pattern:;T@o:RDoc::Markup::Verbatim;[
I"&Rails.application.routes.draw do
;TI"7  Pattern 1 tells some request to go to one place
;TI",  Pattern 2 tell them to go to another
;TI"  ...
;TI"	end
;T:@format0o;	;[I"'The following symbols are special:;T@o;;[I".:controller maps to your controller name
;TI"9:action     maps to an action with your controllers
;T;0o;	;[I"JOther names simply map to a parameter as in the case of <tt>:id</tt>.;T@S:RDoc::Markup::Heading:
leveli:	textI"Resources;T@o;	;[	I"MResource routing allows you to quickly declare all of the common routes ;TI"Nfor a given resourceful controller. Instead of declaring separate routes ;TI"Ofor your +index+, +show+, +new+, +edit+, +create+, +update+ and +destroy+ ;TI"Iactions, a resourceful route declares them in a single line of code:;T@o;;[I"resources :photos
;T;0o;	;[	I"HSometimes, you have a resource that clients always look up without ;TI"Oreferencing an ID. A common example, /profile always shows the profile of ;TI"Qthe currently logged in user. In this case, you can use a singular resource ;TI"Cto map /profile (rather than /profile/:id) to the show action.;T@o;;[I"resource :profile
;T;0o;	;[I"HIt's common to have resources that are logically children of other ;TI"resources:;T@o;;[I"resources :magazines do
;TI"  resources :ads
;TI"	end
;T;0o;	;[
I"LYou may wish to organize groups of controllers under a namespace. Most ;TI"Lcommonly, you might group a number of administrative controllers under ;TI"Gan +admin+ namespace. You would place these controllers under the ;TI"O<tt>app/controllers/admin</tt> directory, and you can group them together ;TI"in your router:;T@o;;[I"namespace "admin" do
;TI"#  resources :posts, :comments
;TI"	end
;T;0o;	;[I"OAlternatively, you can add prefixes to your path without using a separate ;TI"Hdirectory by using +scope+. +scope+ takes additional options which ;TI""apply to all enclosed routes.;T@o;;[I"+scope path: "/cpanel", as: 'admin' do
;TI"#  resources :posts, :comments
;TI"	end
;T;0o;	;[I"BFor more, see <tt>Routing::Mapper::Resources#resources</tt>, ;TI"6<tt>Routing::Mapper::Scoping#namespace</tt>, and ;TI"-<tt>Routing::Mapper::Scoping#scope</tt>.;T@S;
;i;I"Non-resourceful routes;T@o;	;[I"XFor routes that don't fit the <tt>resources</tt> mold, you can use the HTTP helper ;TI"[methods <tt>get</tt>, <tt>post</tt>, <tt>patch</tt>, <tt>put</tt> and <tt>delete</tt>.;T@o;;[I"&get 'post/:id', to: 'posts#show'
;TI"1post 'post/:id', to: 'posts#create_comment'
;T;0o;	;[I"uNow, if you POST to <tt>/posts/:id</tt>, it will route to the <tt>create_comment</tt> action. A GET on the same ;TI"0URL will route to the <tt>show</tt> action.;T@o;	;[I"aIf your route needs to respond to more than one HTTP method (or all methods) then using the ;TI":<tt>:via</tt> option on <tt>match</tt> is preferable.;T@o;;[I"<match 'post/:id', to: 'posts#show', via: [:get, :post]
;T;0S;
;i;I"Named routes;T@o;	;[I"<Routes can be named by passing an <tt>:as</tt> option, ;TI"Kallowing for easy reference within your source as +name_of_route_url+ ;TI"@for the full URL and +name_of_route_path+ for the URI path.;T@o;	;[I"
Example:;T@o;;[
I"# In config/routes.rb
;TI"5get '/login', to: 'accounts#login', as: 'login'
;TI"
;TI"-# With render, redirect_to, tests, etc.
;TI"redirect_to login_url
;T;0o;	;[I"%Arguments can be passed as well.;T@o;;[I"(redirect_to show_item_path(id: 25)
;T;0o;	;[I"LUse <tt>root</tt> as a shorthand to name a route for the root path "/".;T@o;;[I"# In config/routes.rb
;TI"root to: 'blogs#index'
;TI"
;TI"2# would recognize http://www.example.com/ as
;TI"7params = { controller: 'blogs', action: 'index' }
;TI"
;TI"&# and provide these named routes
;TI"/root_url   # => 'http://www.example.com/'
;TI"root_path  # => '/'
;T;0o;	;[I"HNote: when using +controller+, the route is simply named after the ;TI"<method you call on the block parameter rather than map.;T@o;;[I"# In config/routes.rb
;TI"controller :blog do
;TI"%  get 'blog/show',    to: :list
;TI"'  get 'blog/delete',  to: :delete
;TI"%  get 'blog/edit',    to: :edit
;TI"	end
;TI"
;TI"8# provides named routes for show, delete, and edit
;TI"=link_to @article.title, blog_show_path(id: @article.id)
;T;0S;
;i;I"Pretty URLs;T@o;	;[I"2Routes can generate pretty URLs. For example:;T@o;;[
I"Rget '/articles/:year/:month/:day', to: 'articles#find_by_id', constraints: {
;TI"  year:       /\d{4}/,
;TI"  month:      /\d{1,2}/,
;TI"  day:        /\d{1,2}/
;TI"}
;T;0o;	;[I"PUsing the route above, the URL "http://localhost:3000/articles/2005/11/06" ;TI"maps to;T@o;;[I"5params = {year: '2005', month: '11', day: '06'}
;T;0S;
;i;I"'Regular Expressions and parameters;To;	;[I"MYou can specify a regular expression to define a format for a parameter.;T@o;;[
I"controller 'geocode' do
;TI"<  get 'geocode/:postalcode', to: :show, constraints: {
;TI"&    postalcode: /\d{5}(-\d{4})?/
;TI"	  }
;TI"	end
;T;0o;	;[I"LConstraints can include the 'ignorecase' and 'extended syntax' regular ;TI"expression modifiers:;T@o;;[I"controller 'geocode' do
;TI"<  get 'geocode/:postalcode', to: :show, constraints: {
;TI"+    postalcode: /hx\d\d\s\d[a-z]{2}/i
;TI"	  }
;TI"	end
;TI"
;TI"controller 'geocode' do
;TI"<  get 'geocode/:postalcode', to: :show, constraints: {
;TI"*    postalcode: /# Postalcode format
;TI"       \d{5} #Prefix
;TI"       (-\d{4})? #Suffix
;TI"       /x
;TI"	  }
;TI"	end
;T;0o;	;[I"AUsing the multiline modifier will raise an +ArgumentError+. ;TI"EEncoding regular expression modifiers are silently ignored. The ;TI"9match will always use the default encoding or ASCII.;T@S;
;i;I"External redirects;T@o;	;[I"XYou can redirect any path to another path using the redirect helper in your router:;T@o;;[I",get "/stories", to: redirect("/posts")
;T;0S;
;i;I"Unicode character routes;T@o;	;[I"=You can specify unicode character routes in your router:;T@o;;[I"0get "こんにちは", to: "welcome#index"
;T;0S;
;i;I"!Routing to Rack Applications;T@o;	;[I"NInstead of a String, like <tt>posts#index</tt>, which corresponds to the ;TI"Oindex action in the PostsController, you can specify any Rack application ;TI"#as the endpoint for a matcher:;T@o;;[I"*get "/application.js", to: Sprockets
;T;0S;
;i;I"Reloading routes;T@o;	;[I"0You can reload routes if you feel you must:;T@o;;[I"&Rails.application.reload_routes!
;T;0o;	;[I"eThis will clear all named routes and reload config/routes.rb if the file has been modified from ;TI"Dlast load. To absolutely force reloading, use <tt>reload!</tt>.;T@S;
;i;I"Testing Routes;T@o;	;[I"2The two main methods for testing your routes:;T@S;
;i;I"+assert_routing+;T@o;;[	I"*def test_movie_route_properly_splits
;TI"B  opts = {controller: "plugin", action: "checkout", id: "2"}
;TI"0  assert_routing "plugin/checkout/2", opts
;TI"	end
;T;0o;	;[I"\+assert_routing+ lets you test whether or not the route properly resolves into options.;T@S;
;i;I"+assert_recognizes+;T@o;;[	I" def test_route_has_options
;TI"?  opts = {controller: "plugin", action: "show", id: "12"}
;TI"2  assert_recognizes opts, "/plugins/show/12"
;TI"	end
;T;0o;	;[I"MNote the subtle difference between the two: +assert_routing+ tests that ;TI"Ca URL fits options while +assert_recognizes+ tests that a URL ;TI"%breaks into parameters properly.;T@o;	;[I"LIn tests you can simply pass the URL or named route to +get+ or +post+.;T@o;;[I"def send_to_jail
;TI"  get '/jail'
;TI"   assert_response :success
;TI"	end
;TI"
;TI"def goes_to_login
;TI"  get login_url
;TI"  #...
;TI"	end
;T;0S;
;i;I"#View a list of all your routes;T@o;;[I"rails routes
;T;0o;	;[I"CTarget a specific controller with <tt>-c</tt>, or grep routes ;TI"Gusing <tt>-g</tt>. Useful in conjunction with <tt>--expanded</tt> ;TI"&which displays routes vertically.;T:
@fileI"#lib/action_dispatch/routing.rb;T:0@omit_headings_from_table_of_contents_below0o;;[;I",lib/action_dispatch/routing/endpoint.rb;T;0o;;[;I"-lib/action_dispatch/routing/inspector.rb;T;0o;;[;I"*lib/action_dispatch/routing/mapper.rb;T;0o;;[;I"6lib/action_dispatch/routing/polymorphic_routes.rb;T;0o;;[;I"/lib/action_dispatch/routing/redirection.rb;T;0o;;[;I"-lib/action_dispatch/routing/route_set.rb;T;0o;;[;I"0lib/action_dispatch/routing/routes_proxy.rb;T;0o;;[;I"+lib/action_dispatch/routing/url_for.rb;T;0;0;0[[[[[I"
class;T[[:public[[:protected[[:private[[I"
instance;T[[;[[;[[;[[[I"ActiveSupport::Autoload;To;;[;@8;0I"#lib/action_dispatch/routing.rb;T[U:RDoc::Context::Section[i0o;;[;0;0[@8@;@>@A@D@G@J@M@PI"6lib/action_dispatch/testing/assertions/routing.rb;TI"/lib/action_dispatch/testing/integration.rb;TI"ActionDispatch;TcRDoc::NormalModule