Ruby on rails Rails葡萄api版本控制模块结构

Ruby on rails Rails葡萄api版本控制模块结构,ruby-on-rails,api,versioning,grape,grape-api,Ruby On Rails,Api,Versioning,Grape,Grape Api,我正在尝试实现api版本控制,几乎与。但我在rails应用程序中似乎没有正确的模块/文件夹结构,因为我收到了错误消息,如V1不是模块/app/api/V1/xml\u responses/device.rb:3:in'. 目录结构 /app /api - api.rb /v1 -base.rb /xml_responces - device.rb api.rb require 'v1/base.rb' module API cl

我正在尝试实现api版本控制,几乎与。但我在rails应用程序中似乎没有正确的模块/文件夹结构,因为我收到了错误消息,如
V1不是模块/app/api/V1/xml\u responses/device.rb:3:in'.
目录结构

/app
  /api
    - api.rb
    /v1
      -base.rb
      /xml_responces
        - device.rb
api.rb

require 'v1/base.rb'
module  API
  class Base < Grape::API
    mount API::V1 => '/v1/'
  end
end
module API
  module V1
  class ApiV1 < Grape::API
    require 'builder'
    helpers DeviceMethods
    prefix 'api'
    version 'v1', using: :header
  end
  end
end
module API
  module V1
    module XMLResponses::Device
      def self.do_something
        #do_something
      end
    end
  end
end
  mount API::Base => '/'
Routes.rb

require 'v1/base.rb'
module  API
  class Base < Grape::API
    mount API::V1 => '/v1/'
  end
end
module API
  module V1
  class ApiV1 < Grape::API
    require 'builder'
    helpers DeviceMethods
    prefix 'api'
    version 'v1', using: :header
  end
  end
end
module API
  module V1
    module XMLResponses::Device
      def self.do_something
        #do_something
      end
    end
  end
end
  mount API::Base => '/'

我不知道我做错了什么!您能帮助我吗?

请确保您在
应用程序.rb中有这一行

config.paths.add "app/api", glob: "**/*.rb"
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]

正如grape wiki上所建议的那样,我也遇到了类似的问题,但后来偶然发现了这篇帮助我实现目标的伟大文章,它提供了比其他地方更完整的信息。看

看看你的代码,这看起来很有趣:

module XMLResponses::Device
  def self.do_something
你想做这样的事吗

module API
  module V1
    module XMLResponses
      class Device < Grape::API
        resource :device do
          get do { Device.all } # Or whatever
        end
      end
    end
  end
end
模块API
模块V1
模块XMLResponses
类设备
尝试在device.rb文件的顶部要求v1/base.rb。不,这无助于还是相同的模块错误?