【问题标题】:Invalid constant API:: with grape and grape-entity无效的常量 API:: 带有葡萄和葡萄实体
【发布时间】:2016-04-06 09:49:59
【问题描述】:

我正在尝试使用 grape-entity,但我的实体类的命名空间有问题,但我不知道为什么。

我有这个葡萄实体类:

# app/controllers/api/v1/entities/vehicules.rb
module API
  module V1
    module Entities
      class Vehicules < Grape::Entity
        expose :marque
        expose :modele
        expose :user do 
          expose :name
        end
      end
    end
  end
end

还有葡萄类:

# app/controllers/api/v1/vehicules.rb
module API
  module V1
    class Vehicules < Grape::API
      include API::V1::Defaults
      version 'v1' 
      format :json 


      resource :vehicules do
        desc "Return list of vehicules"
          get do
            #authenticate! @todo
            vehicules = Vehicule.find_by(user_id: params['user_id'])
            present vehicules, with API::V1::Entities::Vehicules
          end

当我打电话给curl http://localhost:3000/api/v1/vehicules?user_id=123 时,我在 rails 服务器中有这条消息:

Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:457:in `load':
app/controllers/api/v1/vehicules.rb:21: syntax error, unexpected tCONSTANT, expecting keyword_do or '{' or (' SyntaxError) 
present vehicules, with API::V1::Entities::Vehicules
                           ^

任何帮助都会很棒。

【问题讨论】:

    标签: ruby-on-rails grape-entity


    【解决方案1】:

    with:

    present vehicules, with: API::V1::Entities::Vehicules
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多