所有
我在使用葡萄时遇到错误.
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
Run Code Online (Sandbox Code Playgroud)
事实上,我的api工作并返回xml.经过一段时间的运行,它开始出现问题.显示错误.我的服务器是nginx +乘客.rails2.3.8.+葡萄.任何帮助?
我正在尝试使用json格式对其所有动词进行Grape API回答.问题是我无法以json格式回答路由错误.我甚至无法解救ActionController :: RoutingError.
我已经阅读了这个链接https://github.com/intridea/grape/pull/342并且我已经将cascade指令设置为false,但API仅以纯文本形式回答"Not Found".
$ curl -X GET http://localhost:3000/api/wrong_uri
Not Found
Run Code Online (Sandbox Code Playgroud)
使用详细选项:
$ curl -X GET http://localhost:3000/api/wrong_uri -v
* About to connect() to localhost port 3000 (#0)
* Trying 127.0.0.1... connected
> GET /api/wrong_uri HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:3000
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/html
< Cache-Control: no-cache
< X-Request-Id: 3cc74a78-3295-4c1f-b989-66d6fac50e5c
< X-Runtime: 0.002980
< Server: WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
< Date: Tue, 06 …Run Code Online (Sandbox Code Playgroud) 我正在使用具有活动记录的机架框架,并且没有导轨,因此当我使用carrierwave gem将图像上传到cloudinary时,我收到以下错误.
处理请求时出现意外错误:未初始化的常量Cloudinary :: CarrierWave :: Storage :: Rails
这是一个有趣的忙碌的一周.我正在开发一个Rails项目并包含Grape在实现API中.
API有2个部分
我设置了应用程序,一切正常...
为了说明需要标题,我使用这样的东西......
class ProfilesApi < Grape::API
resource :profiles do
desc 'List all profiles' do
headers Authorization: {
description: 'Validates identity through JWT provided in auth/login',
required: true
}
end
get do
present User.all, with: Presenters::ProfilePresenter
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在问题是我在很多类似的可安装API类中进行了这种描述.
有没有一种方法可以使这种常见(一种继承),所以我不需要用每个Grape方法定义它.
desc 'List all profiles' do
headers Authorization: {
description: 'Validates identity through JWT provided in auth/login',
required: true
}
end
Run Code Online (Sandbox Code Playgroud)
提前谢谢,希望你们周末愉快.
我正在使用Rails和Grape作为API.我只是好奇为什么session[:something]葡萄没有方法?我可以创建cookie,但也不能创建签名的cookie.它给我一个错误.
我正在学习rails5.0.当我学习Ruby时,我知道ruby文件名可以与里面的类名不同.但是当我移动到rails时,我发现ruby文件名和类名必须具有相同的格式.例如,类名将CheckInDetail在check_in_detail.ruby.我还看到模块名称必须与目录名称匹配.例如,模块authentication必须位于authentication目录内.我的结论的一些例子是:
rspec:类名必须基于文件名.grape:类名必须基于文件名.模块名称也必须与目录匹配.如果我不遵循这些约定,编译rails时会抛出异常.我没有在那些库github页面上看到这些约定.对于整个铁路项目,所有图书馆都是如此吗?
我对 groovy 很陌生,ans 正在练习使用 http-builder 包进行 REST 调用,我正在尝试使用 @Grab 注释添加依赖项,但它没有下载依赖项,注释不起作用,
我的代码:
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
def restClient = RESTClient('http://api.icmdb.com')
restClient.contentType = ContentType.JSON
restClient.get(path:'/jokes/random'){response,json->
println response.status
println json
}
Run Code Online (Sandbox Code Playgroud)
我得到的例外:
Caught: groovy.lang.MissingMethodException: No signature of method: com.groovy.practice.RESTCall.RESTClient() is applicable for argument types: (String) values: [http://api.icmdb.com]
groovy.lang.MissingMethodException: No signature of method: com.groovy.practice.RESTCall.RESTClient() is applicable for argument types: (String) values: [http://api.icmdb.com]
Run Code Online (Sandbox Code Playgroud)
所以基本上它没有下载http-builder,因此它没有找到RESTClient类型的签名。
我的常规版本是:2.6.0-alpha-1 Intellij 版本:2017.2.3
有什么可以在 groovy 或 intellij IDE 中启动 Grape 的,任何人都可以帮忙,我被困在这里。
我正在使用葡萄,我想访问rescue_from中的请求参数:
class API < Grape::API
rescue_from Grape::Exceptions::ValidationErrors do |e|
rack_response({
end
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我想编写一个使用Apache HttpClient 4.1的简单Groovy脚本,因为我没有它的jar,我想用Grapes抓住它.到目前为止我在剧本中的所有内容都是......
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.0')
import org.apache.http.impl.client.DefaultHttpClient;
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个时,我得到一个例外..
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]
Run Code Online (Sandbox Code Playgroud)
当我只询问http客户端时,为什么Grapes得到公共记录?如果是因为后者需要前者,那么我是否需要自己明确地获取所有依赖的http客户端jar?我怎么会知道它们是什么?有没有办法告诉Grapes自己做这件事?
groovy jar ruby-grape dependency-management apache-httpclient-4.x
我用宝石,葡萄做api.我试图通过命令得到api urlsrake grape:routes
namespace :grape do
desc "routes"
task :routes => :environment do
API::Root.routes.map { |route| puts "#{route} \n" }
end
end
Run Code Online (Sandbox Code Playgroud)
但是我过了 rake grape:routes
#<Grape::Router::Route:0x007f9040d13878>
#<Grape::Router::Route:0x007f9040d13878>
#<Grape::Router::Route:0x007f9040d13878>
#<Grape::Router::Route:0x007f9040d13878>
...
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西.
version=v1, method=GET, path=/services(.:format)
version=v1, method=GET, path=/services/:id(.:format)
...
Run Code Online (Sandbox Code Playgroud)
我的葡萄实施如下.这很好用.
module API
class Root < Grape::API
version 'v1', using: :path
format :json
helpers Devise::Controllers::Helpers
mount API::Admin::Services
end
end
module API
class Services < Grape::API
resources :services do
resource ':service_id' do
...
end
end
end
end
Run Code Online (Sandbox Code Playgroud)