Hexa's Blog

Add new methods to exist resource routes as collection in Rails

10/09/2015 Ruby on Rails 4

Rails does support built-in CRUD with RESTful. It provides default url for developers. However, there could be a time that developer want to add more method/action to work with exist routes. Hence, this is solution.

This is a default setting for resources of pictures

resources :pictures

This is modification with new upload method which use GET protocol.

resources :pictures do
  collection do
    get 'upload', to: 'pictures#upload'
  end
end