resources
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (13)
- 3.1.0 (14)
- 3.2.1 (3)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (8)
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
resources(*resources, &block)
public
In Rails, a resourceful route provides a mapping between HTTP verbs and URLs and controller actions. By convention, each action also maps to particular CRUD operations in a database. A single entry in the routing file, such as
resources :photos
creates seven different routes in your application, all mapping to the Photos controller:
GET /photos/new POST /photos GET /photos/:id GET /photos/:id/edit PUT /photos/:id DELETE /photos/:id
Resources can also be nested infinitely by using this block syntax:
resources :photos do resources :comments end
This generates the following comments routes:
GET /photos/:id/comments/new POST /photos/:id/comments GET /photos/:id/comments/:id GET /photos/:id/comments/:id/edit PUT /photos/:id/comments/:id DELETE /photos/:id/comments/:id
Supported options
- :path_names
-
Allows you to change the paths of the seven default actions. Paths not specified are not changed.
resources :posts, :path_names => { :new => "brand_new" }
The above example will now change /posts/new to /posts/brand_new
- :module
-
Set the module where the controller can be found. Defaults to nothing.
resources :posts, :module => "admin"
All requests to the posts resources will now go to +Admin::PostsController+.
- :path
-
Set a path prefix for this resource.
resources :posts, :path => "admin"
All actions for this resource will now be at /admin/posts.