如何将子目录包含在Graolo API的自动加载中?

时间:2016-10-05 11:41:24

标签: ruby-on-rails ruby ruby-on-rails-4 grape grape-api

我正在使用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', '/**/')],但没有任何运气。

有任何帮助吗?

0 个答案:

没有答案