我正在使用Grape为Rails项目构建一个API(我将葡萄项目安装在routes.rb
之类的mount Backend::Base => '/'
中。
文件结构类似于:
├── app
│ ├── api
│ │ └── backend
│ │ ├── base.rb
│ │ └── v1
│ │ ├── alerts.rb
│ │ ├── test
│ │ │ └── index.rb
我的application.rb
包括:
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', '*')]
base.rb
:
module Backend
class Base < Grape::API
format :json
prefix :api
mount CanopyBackend::V1::Alerts
mount CanopyBackend::V1::Test::Index
end
end
我的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
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
现在似乎我可以以某种方式访问GET api/v1/alerts
但不 api/v1/test/index
。
我尝试修改config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
中的application.rb
以使其成为config.autoload_paths += Dir[Rails.root.join('app', 'api', '/**/')]
,但没有任何运气。
有任何帮助吗?