Flowdock
method

resources

Importance_3
v3.0.9 - Show latest stable - 1 note - Class: ActionDispatch::Routing::Mapper::Resources
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.

Show source
Register or log in to add new notes.
August 15, 2011
1 thank

The :path option

The path option will actually set the path and not the prefix I have found in Rails 3.0.5.

Example

resources :my_reports, :path => 'my-reports'

All actions for this resource will now be at /my-reports.