Created
March 20, 2014 08:03
-
-
Save rummelonp/9659267 to your computer and use it in GitHub Desktop.
Grape でファイル分ける
This file contains hidden or 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
# app/api/users.rb | |
class Users < Grape::API | |
format :json | |
get do | |
# returns users | |
end | |
get ':id' do | |
# returns user | |
end | |
# nested resources | |
route_param :user_id do | |
mount Users::Books | |
end | |
end | |
# app/api/users/books.rb | |
class Users::Books < Grape::API | |
resource :books do | |
get do | |
# return user books | |
end | |
get ':id' do | |
# return user book | |
end | |
end | |
end | |
# config/routes.rb | |
SomeApp::Application.routes.draw do | |
mount Users => '/api/users' | |
end | |
# config/application.rb | |
module SomeApp | |
class Application < Rails::Application | |
config.autoload_paths += %W(#{config.root}/app/api) | |
end | |
end |
Author
rummelonp
commented
Mar 20, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment