GithubHelp home page GithubHelp logo

isabella232 / routing_concerns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rails/routing_concerns

0.0 0.0 0.0 107 KB

Abstract common routing resource concerns to cut down on duplication.

License: MIT License

Ruby 100.00%

routing_concerns's Introduction

Routing Concerns

Abstract common routing resource concerns to cut down on duplication.

Code before:

BCX::Application.routes.draw do
  resources :calendar_events do
    get :past, on: :collection
    resources :comments
  end

  resources :messages  { resources :comments }
  resources :forwards  { resources :comments }
  resources :uploads   { resources :comments }
  resources :documents { resources :comments }
  resources :todos     { resources :comments }
  
  resources :projects, defaults: { bucket_type: 'project' } do
    post :trash, :restore, on: :member
  
    resources :messages, except: [ :new ] do
      post :trash, :restore, on: :member
      resources :image_attachments, only: :index
    end
  
    resources :forwards do
      member do
        get  :content
        post :trash, :restore
      end
  
      resources :image_attachments, only: :index
    end
  
    resources :uploads do
      post :trash, :restore, on: :member
      resources :image_attachments, only: :index
    end
  
    resources :todolists do
      get :more, :completed, on: :collection
      post :trash, :restore, on: :member
    end
  
    resources :todos do
      post :toggle, :trash, :restore, on: :member
    end
  
    resources :comments do
      post :trash, on: :member
      resources :image_attachments, only: :index
    end
  end
end

Code after:

BCX::Application.routes.draw do
  concern :commentable do
    resources :comments
  end
  
  concern :trashable do
    post :trash, :restore, on: :member
  end

  concern :image_attachable do
    resources :image_attachments, only: :index
  end

  resources :calendar_events, concerns: :commentable do
    get :past, on: :collection
  end

  resources :messages, :forwards, :uploads, :documents, :todos, concerns: :commentable

  resources :projects, concerns: :trashable, defaults: { bucket_type: 'project' } do
    resources :messages, :uploads, :comments, concerns: [:trashable, :image_attachable]
  
    resources :forwards, concerns: [:trashable, :image_attachable] do
      get :content, on: :member
    end
  
    resources :todolists, concerns: :trashable do
      get :more, :completed, on: :collection
    end
  
    resources :todos, concerns: :trashable do
      post :toggle, on: :member
    end
  end
end

Compatibility

This plugin was designed as a proof-of-concept for a feature that's destined for Rails 4. It has only been tested on Rails 3.2+, but may work on earlier versions as well.

routing_concerns's People

Contributors

dhh avatar jeremy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.