预期 ../app/api/api.rb 在 rails 中定义 Api

Expected ../app/api/api.rb to define Api in rails

我正在尝试使用 Grape 创建一个 API。为了使这个 API 工作是指这个网站 - One Grape API. I even saw these posts on Whosebug 但它不工作。 代码如下: /app/api/api.rb

  class API < Grape::API
   prefix 'api'
   version 'v1', using: :path
   format :json
   mount Code::Coding
  end

/app/api/code/coding.rb:

module Code
 class Coding < Grape::API
    resource :exam_questions do
      desc "getting all the questions"
      get do
            ExamQuestion.first
      end
    end
 end
end

/app/config/application.rb:

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

/app/config/routes.rb:

mount Coders::API => '/'

但是我一直收到这个错误

Expected ../app/api/api.rb to define Api

好的,现在我将 api 文件移动到名为 Coders 的文件夹中,并且没有错误。 所以文件结构是这样的:

app/api/coders/api.rb

module Coders
 class API < Grape:: API
  #code goes here
 end
end

和app/api/coders/code/coding.rb

 module Coders
  module Code
   class Coding < Grape::API

    resource :exam_questions do
    desc "getting all the questions"
    get do
         ExamQuestion.first
    end
   end

  end
 end
end

现在我已经尝试了几乎所有的排列和组合来访问它,但我无法获得我可以访问问题的路径,它一直显示 404 错误。

运行 rake routes 给出: coders_api_api/Coders::API

有什么方法可以找到访问我的方法的链接。

我得到了问题的答案,在尝试了不同的 links 之后,最终它与这个 link 一起工作:locahost:3000/api/v1/exam_questions 没有 。json 这就是我犯的错误。