- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
对于我的其中一种方法,以下方法不起作用。我几乎直接从官方文档中复制了所有内容:
params do
requires :authenticationType, type: Array[String], values: ['LOCAL', 'AD']
given authenticationType: ->(val) { val == 'LOCAL' } do
requires :admin, type: String, allow_blank: false, regexp: /^[\w\.\@-]{1,64}$/
requires :password, type: String, allow_blank: false, regexp: /^[\w\.\@-]{1,64}$/
end
end
它在“给定”行上给出错误。任何人都知道出了什么问题。我的目标:仅当 'authenticationType' == 'LOCAL' 时,用户才应提供 'admin' 和 'password'
错误:
[ 2017-03-03 00:39:18.4848 14970/7f5d0603f700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /vagrant/masterapi: An error occurred while starting up the preloader. Error ID: 0bd79149 Error details saved to: /tmp/passenger-error-3OYsdJ.html Message from application: Grape::Exceptions::UnknownParameter (Grape::Exceptions::UnknownParameter)
/usr/local/lib/ruby/gems/2.3.0/gems/grape-0.16.2/lib/grape/dsl/parameters.rb:170:inblock in given'<br/>
each'
/usr/local/lib/ruby/gems/2.3.0/gems/grape-0.16.2/lib/grape/dsl/parameters.rb:169:in
/usr/local/lib/ruby/gems/2.3.0/gems/grape-0.16.2/lib/grape/dsl/parameters.rb:169:ingiven' /vagrant/masterapi/controllers/papi_controller.rb:93:in
block in '
最佳答案
'given' 仅从 grape 版本 0.17 开始接受 proc,在合并请求 (MR) 中实现 1443 .因此,您应该更新,或者如果这不可行,请尝试将此 MR 向后移植到 0.16.2。
Here's您的版本的自述文件。
此外,在您的示例中,authenticationType
参数是 Array[String]
类型,因此(至少在 grape 0.17 中),proc 将收到一个 哈希::数组
。
这意味着:
->(val) { val == 'LOCAL' }
应该是
->(val) { val.first == 'LOCAL' }
关于Ruby/Grape 在特定条件下需要参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42568710/
我的 Grape 端点中有这样一行来检查 POST 正文的内容,以提供测试端点: return 'OK' if request.body.string == 'TEST' 在我笔记本电脑上的开发环境中
我正在尝试在没有 grape-api gem 的情况下使用 grape-entity。所以只需将它用作原始 Rails Controller 的序列化器即可。 当尝试通过以下方式展示我的资源时: 呈现
在 Grape 中,如果您使用 错误! 方法它会抛出一个错误并且永远不会调用 Grape::Endpoint “after”回调。 我希望应用程序在出错时调用后 Hook !已被调用。 我添加了这个中
我正在尝试使用葡萄来制作 Rest API。 为此,我在一个目录中创建了一个 config.ru 文件: require 'rubygems' require 'rack' require './gr
我想做的是在葡萄和葡萄实体 gem 之间重用类型和描述。 在文档中我阅读了以下内容: You can use entity documentation directly in the params b
我想在我的 groovy 程序中使用 @Grape,但我的程序由几个文件组成。 Groovy Grape page上的例子所有人似乎都假设您的脚本将由一个文件组成。我怎样才能做到这一点?我应该将它添加
我正在尝试使用org.xhtmlrenderer:core-renderer:R8pre2在常规脚本中,但我收到链接错误: Caught: java.lang.LinkageError: loader
我需要创建一个POST,可以在同一请求中上传多个文件,但我不知道如何用grape编写它。现在只上传一个文件,这就是我正在做的事情,并且工作正常: desc 'Creates a new attachm
对于我的其中一种方法,以下方法不起作用。我几乎直接从官方文档中复制了所有内容: params do requires :authenticationType, type: Array[String],
如何让 Grape 中的多个路由参数在 grape 中工作? 我可以使这条路线可行: .../api/company/:cid 但是当我尝试这样做时: .../api/company/:cid/mem
您如何配置 Grape 以在默认位置之外的位置查找自定义配置文件 ~/.groovy/grapeConfig.xml ?不幸的是,官方文档位于 http://groovy.codehaus.org/G
我相信我已经正确配置了所有内容,这样 grape 应该询问存储库是否有新的修订版,但事实并非如此。只要 jar 存在于 .groovy/grapes 中,它就会使用它。 我正在通过我们应用程序的 AP
我对 Ruby 有点陌生,但我在 Ruby 中使用 Grape API 编写了以下代码。每次点击 GET/api/v1/foo 时,我都会调用 @data = YAML.load(),在 Grape
我使用 Ember 作为我的前端和 Grape API 来为我的 API 提供服务。 前端发送类似: { "service"=>{ "name"=>"Name", "duratio
我在部署从 groovy 脚本创建的 JAR 时遇到问题,我认为这是因为在脚本中我使用 Grape 的 Grab 功能来引入一些库,然后当我构建 JAR 时,这些库是'包含在类路径或任何东西中。 我怎
因此,我正在使用 Rails 4 和 Grape Api 开发这个系统。基本上,它汇总了有关在车辆上执行的维护服务的信息。我的模型定义如下: # service.rb class Service <
我正在使用 Grape redtful-api。我无法继承 Grape 中的 common_params。我定义了共同 _params 类 API1 并在 API2 中调用它会引发错误。如何更改代码以
我有一个 format :xml Grape::API 对于删除请求,我想返回一个空响应。 我尝试输入的所有内容,true,false,nil,它都会尝试转换为 xml。我该怎么做呢? 谢谢 最佳答案
我正在尝试使用 Rails 和 Grape 构建一组 API。用户模型如下: { "email": "foo@bar.com" "name": "Foo Bar" } 现在,在 API
这个问题已经有答案了: Groovy - Grab - download failed (9 个回答) 已关闭 6 年前。 我有一个 Groovy 文件,其中包含以下代码: @Grab(group='
我是一名优秀的程序员,十分优秀!