I'm using Grape to build an API for a Rails project (I'm mounting the grape project in rails routes.rb
something like mount Backend::Base => '/'
).
The files structure is something like:
├── app
│ ├── api
│ │ └── backend
│ │ ├── base.rb
│ │ └── v1
│ │ ├── alerts.rb
│ │ ├── test
│ │ │ └── index.rb
My application.rb
includes:
config.paths.add "app/api", glob: "**/*.rb"
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
For base.rb
:
module Backend
class Base < Grape::API
format :json
prefix :api
mount CanopyBackend::V1::Alerts
mount CanopyBackend::V1::Test::Index
end
end
My alerts.rb
:
module Backend
module V1
class Alerts < Grape::API
include Backend::V1::Defaults
resource :alerts do
get do
"alerts"
end
end
end
end
end
And test/index.rb
:
module Backend
module V1
module Test
class Index < Grape::API
include Backend::V1::Defaults
resource :index do
get do
"index"
end
end
end
end
end
end
Now it seems I can access GET api/v1/alerts
but not api/v1/test/index
somehow.
I tried to modify config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
in application.rb
to make it config.autoload_paths += Dir[Rails.root.join('app', 'api', '/**/')]
but without any luck.
Any help?