Rails,Grape实体抛出:未初始化的常量Grape :: Entity

时间:2015-03-25 16:31:16

标签: ruby-on-rails ruby json grape

在rails项目中,我创建了api文件夹,并将此代码添加到我的application.rb文件中:

config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]

在我的api文件夹中,我创建了game_server.rb文件:

module GameServer

  module Entities
   class Test < Grape::Entity
     expose :id
   end
  end


class API < Grape::API
   version 'v1', using: :path
   prefix :api
   format :json

   get :details do
      present Basis.all, with: GameServer::Entities::Test
   end

 end
end

GameServer模块中的所有代码。当我在浏览器中点击http://localhost:3000/api/v1/details时,我发现此错误: uninitialized constant Grape::Entity

我甚至试图将我的Entities模块放在其他文件中,但仍无效。

为什么?

2 个答案:

答案 0 :(得分:0)

您正在使用旧版葡萄,更改您的葡萄版本:

gem 'grape', '~> 0.11.0'

答案 1 :(得分:0)

您可以参考此存储库:https://github.com/philcallister/rails-grape-entity

添加

  

宝石'葡萄'

     

宝石'葡萄实体'

进入Gemfile