resources

resources(*resources, &block) Instance Public methods 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 GET /photos/new POST /photos GET /photos/:id GET /p

resource

resource(*resources, &block) Instance Public methods Sometimes, you have a resource that clients always look up without referencing an ID. A common example, /profile always shows the profile of the currently logged in user. In this case, you can use a singular resource to map /profile (rather than /profile/:id) to the show action: resource :profile creates six different routes in your application, all mapping to the Profiles controller (note that the controller is named after

new

new() Instance Public methods

nested

nested() Instance Public methods

namespace

namespace(path, options = {}) Instance Public methods See ActionDispatch::Routing::Mapper::Scoping#namespace

member

member() Instance Public methods To add a member route, add a member block into the resource block: resources :photos do member do get 'preview' end end This will recognize /photos/1/preview with GET, and route to the preview action of PhotosController. It will also create the preview_photo_url and preview_photo_path helpers.

match

match(path, *rest) Instance Public methods match 'path' => 'controller#action' match 'path', to: 'controller#action' match 'path', 'otherpath', on: :member, via: :get

collection

collection() Instance Public methods To add a route to the collection: resources :photos do collection do get 'search' end end This will enable Rails to recognize paths such as /photos/search with GET, and route to the search action of PhotosController. It will also create the search_photos_url and search_photos_path route helpers.

put

put(*args, &block) Instance Public methods Define a route that only recognizes HTTP PUT. For supported arguments, see match put 'bacon', to: 'food#bacon'

post

post(*args, &block) Instance Public methods Define a route that only recognizes HTTP POST. For supported arguments, see match post 'bacon', to: 'food#bacon'