首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无效常量API::与葡萄和葡萄实体

无效常量API::与葡萄和葡萄实体
EN

Stack Overflow用户
提问于 2016-04-06 09:49:59
回答 1查看 85关注 0票数 0

我正在尝试使用grape-entity,我在实体类的名称空间上遇到了问题,但我无法理解原因。

我有一个葡萄实体类:

代码语言:javascript
复制
# 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

葡萄级:

代码语言:javascript
复制
# 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服务器中有这样的消息:

代码语言:javascript
复制
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
                           ^

任何帮助都会很好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-06 09:54:02

with:

代码语言:javascript
复制
present vehicules, with: API::V1::Entities::Vehicules
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36447498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档