Routes

Dos

  • Comment each sections
  • Use scope, namespace, and resources as much as possible.
  • Use except and only on resources when needed.
  • Use member and collection on resources when needed.
  • Use default: {format: 'json'} for API's routes

Don'ts

  • Use plain routes like get "events/:id", to: "events#show", as: :event

Code

Rails::Application.routes.draw do

  namespace :api, default: {format: 'json'} do
    resources :events, except: [:delete] do
      member do
        get "logs"
        post "restart"
      end

      collection do
        get "recents"
      end
    end
  end

  scope :static do
    get "about", to: "pages#about"
    get "contact", to: "pages#contact"
  end
end

results matching ""

    No results matching ""