问题标签 [grape]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2002 浏览

api - Rails 4 葡萄 API ActionController::RoutingError

我正在尝试让葡萄 API 以 json 格式回答其所有动词。问题是我无法回答 json 格式的路由错误。我什至无法挽救 ActionController::RoutingError。

我已阅读此链接https://github.com/intridea/grape/pull/342并将级联指令设置为 false,但 API 仅以纯文本形式回答“未找到”。

带有详细选项:

我的葡萄文件 /app/api/api.rb

0 投票
1 回答
66 浏览

ruby - ActiveRecord::Base has_many 获取所有给定父级

问题

下面我给出了我当前的 API 结果,但是,鉴于执行的 SQL 不是我的预期或期望结果。谁能帮助我获得第二个 SQL 查询结果而不是第一个?

楷模

控制台游戏.rb

配置.rb

API

调试控制台

D,[2014-05-06T15:11:59.071493 #31068] 调试——:控制台游戏负载(0.4 毫秒)选择console_game.* 从console_game 哪里console_gamevalue=“战地 3”D,[2014-05-06T15:11:59.073289 #31068] 调试 -- :配置加载(0.3 毫秒)选择configuration.* 从configuration 哪里configurationconsole_game_idIN (2) 127.0.0.1 - - [06/May/2014 15:12:08] “GET /configuration/game HTTP/1.1”200 34 25.9740

结果 - 获取 /configuration/game

期望的结果 - 获取 /configuration/game

注意:这张表上有很多外国索引,我想解决它们,但也许那是另一天。

的结果ConsoleGame.where(value: 'Battlefield 3').includes(:configurations).as_json(include: :configurations)

0 投票
1 回答
2823 浏览

ruby - Resolve all ActiveRecord Associations using Grape::Entity (SQL Join)

Question

I've been messing with ruby, grape, grape-entity, and activerecord. Everything is going swimmingly however I can't see to get the desired result from grape-entity when using the using keyword for a expose item.

My goal is to basically resolve all my activerecord associations, and then return the resulting JSON. This way I have a complete object for presentation for my configurations API method.

If you need more information, please ask i'll happily provide anything and everything.

Notes: I am using rackup as my server, i'm not using rails at all.

Classes

console_game.rb

cloud_user.rb

device.rb

console_system.rb

configuration.rb


Grape API

Error

NoMethodError at /configuration undefined method `id' for 4:Fixnum

Ruby /Library/Ruby/Gems/2.0.0/gems/grape-entity-0.4.2/lib/grape_entity/entity.rb: in delegate_attribute, line 465 Web GET localhost/configuration

Removing :using to get it to "work"

configuration.rb

JSON Result

Desired Result

0 投票
1 回答
230 浏览

ruby - Hashie::Mash 存储为字符串并且无法将其提取回来

我正在使用 Grape 并将数据存储在 postgres hstore 数据字段中。但问题在于它将 Hashie::Mash 存储为字符串而不是对象。

但是在更新之后,如果您获取该对象数据字段,那么它会显示

0 投票
0 回答
183 浏览

apache - 带有 Grape API 的 Sinatra 应用程序

我正在与 Grape 一起运行 Sinatra 应用程序。我在 SO 上看到了关于如何同时运行这两者或任何其他 Rack 兼容解决方案的其他帖子,尽管我的困惑有点不同。

我需要先说明一下,我注意到的大多数解决方案都可以将两者一起运行以将 Grape 安装在某些路线上,尽管这不是我正在做的事情。我只是简单地说:Rack::Cascade.new[SinatraApp,GrapeAPI] 一切正常,除了当我部署到 Apache 时,我注意到 stderr 使用 404 注销了对 api 的调用,即使它正确返回了我的 JSON。

default_format :json在 Grape 路线上设置 mime 类型。那只是没有发生吗?我确实有角度通过 $http 服务调用 Grape 并在开发工具中确认我正在接收application/json类型。

我在这里做错了什么?

0 投票
0 回答
722 浏览

ruby-on-rails - Grape::API – RuntimeError: 在自动加载常量用户时检测到循环依赖

我正在使用 Rails 4.1 测试 Grap API 框架,但我被这个循环依赖所困扰。知道为什么我得到它吗?

应用程序/api/v1/user.rb

应用程序/api/api.rb

应用程序/模型/user.rb

0 投票
1 回答
8944 浏览

ruby-on-rails - 为什么我使用 Rails 和葡萄得到“无法自动加载常量”?

我想为 Android 应用程序做一个 API。搜索时,我找到了{grape}。我正在关注本教程,但在启动 Rails 服务器时遇到问题:

我的目录:

和文件:

为什么我会收到此错误?我正在使用 Ruby 1.9.3p484 和 Rails-4.0.2。

0 投票
0 回答
1070 浏览

ruby-on-rails - 如何在葡萄中传递查询字符串和POST参数

我正在使用. 我想创建一个带有参数和查询字符串参数的 post 方法。如何使用它们?谁能给我一个很好的例子?grape Restful APIPOST

我知道传递查询字符串参数(键,符号)如下。但是如何使用 POST 参数。我想传递帖子参数(比如名字,id)。如何在代码中做到这一点。

https://www.abc.com/api/v2/list?key=abc&sign=xyz

我的代码如下

除此之外,我还想传递帖子参数(比如名称、id)。怎么做?

0 投票
1 回答
1159 浏览

ruby-on-rails - 如何强制 Grape 只接受并返回 JSON?

我如何限制我的 API 在 Rails 和 Grape 上仅接受和响应 json 格式,我已经尝试format :json过我的 Grape 控制器并且(例如)我可以在 example.com/api/v1/ping.json 上访问它,但是我也可以通过example.com/api/v1/ping.xml、example.com/api/v1/ping.foobar访问它,扩展列表还在继续……

我想做的事情是在 example.com/api/v1/ping.not_json_extensions 上抛出错误

我正在使用:

  • 导轨 (4.1.1)
  • 葡萄 (0.7.0)

/config/routes.rb

/控制器/api/base.rb

/controllers/api/v1/base.rb

结尾

/controllers/api/v1/ping.rb

结尾

0 投票
1 回答
4740 浏览

ruby - 如何为葡萄制作对象数组

我正在为 Rails 应用程序使用 Grape Api 构建 API。

我现在正在尝试的是这种形式:在此处输入图像描述

这是输出:

我省略了 json 的某些部分以使其更短。

我需要的是有一个数组,或者ssa直到现在都无法做到。它制作了一个ssa只有一个对象的数组。

在我的 API 控制器中,我有以下代码: