Created
March 2, 2015 19:26
-
-
Save bricker/b9ae61ded579e1ab0f0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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