v3.0.5 - 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

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

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

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+.


  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.


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

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