问题标签 [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.
api - Rails 4 葡萄 API ActionController::RoutingError
我正在尝试让葡萄 API 以 json 格式回答其所有动词。问题是我无法回答 json 格式的路由错误。我什至无法挽救 ActionController::RoutingError。
我已阅读此链接https://github.com/intridea/grape/pull/342并将级联指令设置为 false,但 API 仅以纯文本形式回答“未找到”。
带有详细选项:
我的葡萄文件 /app/api/api.rb
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_game
。value
=“战地 3”D,[2014-05-06T15:11:59.073289 #31068] 调试 -- :配置加载(0.3 毫秒)选择configuration
.* 从configuration
哪里configuration
。console_game_id
IN (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)
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
ruby - Hashie::Mash 存储为字符串并且无法将其提取回来
我正在使用 Grape 并将数据存储在 postgres hstore 数据字段中。但问题在于它将 Hashie::Mash 存储为字符串而不是对象。
但是在更新之后,如果您获取该对象数据字段,那么它会显示
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
类型。
我在这里做错了什么?
ruby-on-rails - Grape::API – RuntimeError: 在自动加载常量用户时检测到循环依赖
我正在使用 Rails 4.1 测试 Grap API 框架,但我被这个循环依赖所困扰。知道为什么我得到它吗?
应用程序/api/v1/user.rb
应用程序/api/api.rb
应用程序/模型/user.rb
ruby-on-rails - 如何在葡萄中传递查询字符串和POST参数
我正在使用. 我想创建一个带有参数和查询字符串参数的 post 方法。如何使用它们?谁能给我一个很好的例子?grape
Restful API
POST
我知道传递查询字符串参数(键,符号)如下。但是如何使用 POST 参数。我想传递帖子参数(比如名字,id)。如何在代码中做到这一点。
https://www.abc.com/api/v2/list?key=abc&sign=xyz
我的代码如下
除此之外,我还想传递帖子参数(比如名称、id)。怎么做?
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
结尾
ruby - 如何为葡萄制作对象数组
我正在为 Rails 应用程序使用 Grape Api 构建 API。
我现在正在尝试的是这种形式:
这是输出:
我省略了 json 的某些部分以使其更短。
我需要的是有一个数组,或者ssa
直到现在都无法做到。它制作了一个ssa
只有一个对象的数组。
在我的 API 控制器中,我有以下代码: