module ActionDispatch::Routing::Mapper::Resources
def resources(*resources, &block)
# resource actions are at /admin/posts.
resources :posts, module: "admin"
# routes call Admin::PostsController
=== Examples
Allows you to override the default param name of +:id+ in the URL.
[:param]
segment or disable it by supplying +false+.
Allows you to specify the default value for optional +format+
[:format]
sekret_comment DELETE /comments/:id(.:format)
sekret_comment PATCH/PUT /comments/:id(.:format)
sekret_comment GET /comments/:id(.:format)
edit_sekret_comment GET /comments/:id/edit(.:format)
new_post_comment GET /posts/:post_id/comments/new(.:format)
post_comments POST /posts/:post_id/comments(.:format)
post_comments GET /posts/:post_id/comments(.:format)
The +comments+ resource here will have the following routes generated for it:
end
end
resources :comments, shallow: true
resources :posts do
scope shallow_prefix: "sekret" do
Prefixes nested shallow route names with specified prefix.
[:shallow_prefix]
comment DELETE /sekret/comments/:id(.:format)
comment PATCH/PUT /sekret/comments/:id(.:format)
comment GET /sekret/comments/:id(.:format)
edit_comment GET /sekret/comments/:id/edit(.:format)
new_post_comment GET /posts/:post_id/comments/new(.:format)
post_comments POST /posts/:post_id/comments(.:format)
post_comments GET /posts/:post_id/comments(.:format)
The +comments+ resource here will have the following routes generated for it:
end
end
resources :comments, shallow: true
resources :posts do
scope shallow_path: "sekret" do
Prefixes nested shallow routes with the specified path.
[:shallow_path]
Set shallow: false on a child resource to ignore a parent's shallow parameter.
to be shortened to just /comments/1234.
as a comment on a blog post like /posts/a-long-permalink/comments/1234
This allows URLs for resources that otherwise would be deeply nested such
resources :comments, only: [:show, :edit, :update, :destroy]
end
resources :comments, except: [:show, :edit, :update, :destroy]
resources :posts do
Is the same as:
end
resources :comments
resources :posts, shallow: true do
generates shallow routes for all nested resources.
Generates shallow routes for nested resource(s). When placed on a parent resource,
[:shallow]
resources :cows, except: [:show, :index]
resources :cows, except: :show
Generate all routes except for the given actions.
[:except]
resources :cows, only: [:show, :index]
resources :cows, only: :show
Only generate routes for the given actions.
[:only]
The resource and all segments will now route to /postings instead of /posts.
resources :posts, path: 'postings'
Allows you to change the path prefix for the resource.
[:path]
The above example will now change /posts/new to /posts/brand_new.
resources :posts, path_names: { new: "brand_new" }
Actions not specified are not changed.
Allows you to change the segment component of the +edit+ and +new+ actions.
[:path_names]
Takes same options as match[rdoc-ref:Base#match] as well as:
=== Options
DELETE /photos/:photo_id/comments/:id
PATCH/PUT /photos/:photo_id/comments/:id
GET /photos/:photo_id/comments/:id/edit
GET /photos/:photo_id/comments/:id
POST /photos/:photo_id/comments
GET /photos/:photo_id/comments/new
GET /photos/:photo_id/comments
This generates the following comments routes:
end
resources :comments
resources :photos do
Resources can also be nested infinitely by using this block syntax:
DELETE /photos/:id
PATCH/PUT /photos/:id
GET /photos/:id/edit
GET /photos/:id
POST /photos
GET /photos/new
GET /photos
the +Photos+ controller:
creates seven different routes in your application, all mapping to
resources :photos
routing file, such as
to particular CRUD operations in a database. A single entry in the
and URLs and controller actions. By convention, each action also maps
In Rails, a resourceful route provides a mapping between HTTP verbs
def resources(*resources, &block) options = resources.extract_options!.dup if apply_common_behavior_for(:resources, resources, options, &block) return self end with_scope_level(:resources) do options = apply_action_options options resource_scope(Resource.new(resources.pop, api_only?, @scope[:shallow], options)) do yield if block_given? concerns(options[:concerns]) if options[:concerns] collection do get :index if parent_resource.actions.include?(:index) post :create if parent_resource.actions.include?(:create) end new do get :new end if parent_resource.actions.include?(:new) set_member_mappings_for_resource end end self end