问题标签 [grape-api]
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.
ruby-on-rails - 如何将 CanCan 与葡萄一起使用?
我想在我的 API 中使用 CanCan 进行授权。例如,如何使用authorize!
Grape::API 模块中的方法?现在,当我尝试使用它时,它会返回给我:
undefined method 'authorize!' for #<Grape::Endpoint:0xca39664>
ruby - 如何在 Grape API (Ruby) 中验证参数的互斥性
使用 Grape 定义 API 时,有一种非常方便的方法可以验证参数的存在和类型,例如:
但是,我看不到指定两个参数互斥的便捷方法。EG它会是这样的:
我对解决此问题的最便捷方法的建议感兴趣。
ruby-on-rails - 如何通过应用程序访问变量
我有一个这样分配的变量:
cryptsy = Cryptsy::API::Client.new(key, secret)
我怎样才能使这个变量在整个应用程序中都可以访问?
目前它在应用程序控制器中,但我正在使用 GRAPE gem 来创建一个简单的 api。我需要能够访问 /app/api/v1/bla.rb 中的变量和 v1 文件夹中的其他文件。
ruby - Rails4 + Json API : Increase detail of response
I'm a newbie on RoR (and Ruby). I need a little help about a json response (with Grape).
This is the sample:
Now this is the result of Events.all
in Rails, but I want to make for each event a query for the place, to have more data instead only id. I'm sure that new lambda function can help me, but for now I have no idea about to make it. I'm trying without success...
Thanks in advance
UPDATE
Desired result
ruby-on-rails - 将参数传递给具有葡萄实体的模型方法
如何使用葡萄实体将参数传递给模型方法?
我想在展示物品时检查current_user是否喜欢物品,所以我建立了一个模型user_likes?
方法:
但我不知道如何将 current_user 发送到葡萄实体模型:
在葡萄 api 中:
我觉得 current_user 可能应该从最后一段代码发送,但我不知道该怎么做:(
有什么想法吗 ?谢谢 !
ruby-on-rails - Rails Grape API 版本控制
我正在尝试使用 Rails 4.0.4 和 Grape 0.7.0 为 REST API 创建一个骨架,其行为如下:
调用特定版本的 API:
默认调用 API:
我一直在尝试,但我无法获得所需的行为。我最终在我的 rails 应用程序中得到了以下文件:
应用程序/api/api.rb
应用程序/api/api_v1.rb
应用程序/api/api_v2.rb
应用程序/配置/路由.rb
使用上述文件,无论我在 curl 命令中指定哪个版本,我都会得到默认行为。-
ruby-on-rails - Grape API + Active Record Wrapping Transaction
我们有葡萄 API,但我想知道我们是否可以在每次请求时用活动记录事务包装它。
在进行交易的活动记录中,我们可以这样做:
如何将它包装到葡萄 API 中?
据我所知,在 Grape API 中,我们可以实现before方法和after方法。
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-on-rails - Grape API files in Rails not reloading
In development mode, the Grape API files in our Rails app aren't reloading as they should. We've tried the suggested approach in the Grape README, and referred to what seems to be the key SO post on it (Ruby on Rails 3 - Reload lib directory for each request) but it's not working for some reason.
In the config/application.rb:
And in initializers/reload_api.rb:
When I change a file under app/api, I can see the "RELOADING!" message in the log so I know the api_reloader callback is being invoked. But the changes are not taking effect. This makes me suspect the config.autoload_paths, but it all looks correct.
This is using Rails 3.2. Suggestions would be fantastic, since obviously it's super-annoying to not have reloading working on this stuff.
ruby-on-rails - 如何对葡萄参数进行消毒
我想批量更新实体的属性。
如何正确消毒来自葡萄的参数?
这是我关于参数的控制台日志: