rockdrilla

caustic config/routes.rb

Sep 19th, 2018
709
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def omgwtf_resources(controller, single, plural)
  2.   scope "/#{single}", controller: controller do
  3.     match ''         => :index,  as: plural,           via: :get
  4.     match 'new'      => :new,    as: "new_#{single}",  via: :get
  5.     match 'new'      => :create, as: '',               via: :post
  6.     match ':id'      => :show,   as: "#{single}",      via: :get
  7.     match ':id/edit' => :edit,   as: "edit_#{single}", via: :get
  8.     match ':id'      => :update, as: '',               via: [:put, :patch]
  9.     match ':id'      => :delete, as: '',               via: :delete
  10.   end
  11. end
  12.  
  13. Rails.application.routes.draw do
  14.   root to: 'common#index'
  15.  
  16.   controller :sessions do
  17.     get   '/login'  => :new,     as: 'login'
  18.     post  '/login'  => :create
  19.     match '/logout' => :destroy, as: 'logout', via: :all
  20.   end
  21.  
  22.   ## resources :users
  23.   omgwtf_resources :users, 'user', 'users'
  24.  
  25.   ## resources :domains
  26.   omgwtf_resources :domains, 'domain', 'domains'
  27. end
RAW Paste Data