Skip to content

Instantly share code, notes, and snippets.

@bricker
Created March 2, 2015 19:26
Show Gist options
  • Save bricker/b9ae61ded579e1ab0f0a to your computer and use it in GitHub Desktop.
Save bricker/b9ae61ded579e1ab0f0a to your computer and use it in GitHub Desktop.
module Routedraw
def self.define_api_routes(routes: Rails.application.routes,
version: :v1,
&block)
routes.draw do
namespace :api, defaults: { format: :json } do
namespace version do
# yield self to pass the current context to the block
yield self
end
end
end
end
end
require 'routedraw'
Rails.application.routes.draw do
resources :posts
Routedraw.define_api_routes do |r|
r.resources :comments
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment