我想使用grape来通过命令行安装库.所以我发出了命令:
grape -V install org.apache.derby derby 10.5.3.0
Run Code Online (Sandbox Code Playgroud)
Grape应使用位于http://127.0.0.1:8081/artifactory/webapp/home.html的Maven存储库.我该如何配置?
启用详细模式后,我在日志中看到:
:: loading settings :: url = jar:file:/opt/groovy-1.7.2/lib/ivy-2.1.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
no default ivy user dir defined: set to /home/alexyz/.ivy2
including url: jar:file:/opt/groovy-1.7.2/lib/ivy-2.1.0.jar!/org/apache/ivy/core/settings/ivysettings-public.xml
no default cache defined: set to /home/alexyz/.ivy2/cache
including url: jar:file:/opt/groovy-1.7.2/lib/ivy-2.1.0.jar!/org/apache/ivy/core/settings/ivysettings-shared.xml
including url: jar:file:/opt/groovy-1.7.2/lib/ivy-2.1.0.jar!/org/apache/ivy/core/settings/ivysettings-local.xml
including url: jar:file:/opt/groovy-1.7.2/lib/ivy-2.1.0.jar!/org/apache/ivy/core/settings/ivysettings-main-chain.xml
including url: jar:file:/opt/groovy-1.7.2/lib/ivy-2.1.0.jar!/org/apache/ivy/core/settings/ivysettings-default-chain.xml
settings loaded (89ms)
default cache: /home/alexyz/.ivy2/cache
default resolver: default
-- 5 resolvers:
shared [file]
default [chain] [local, main]
local [file]
public [ibiblio]
main [chain] [shared, public]
:: resolving dependencies :: caller#all-caller;working …Run Code Online (Sandbox Code Playgroud) 有人可以解释为什么即使我已经使用Grape安装了依赖项,Groovy也无法找到JDBC驱动程序?
$ grape --version
Groovy Version: 1.7.7 JVM: 1.6.0_20
$ grape install org.apache.derby derby 10.5.3.0
:: loading settings :: url = jar:file:/opt/groovy-1.7.7/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: caller#all-caller;working
confs: [default]
found org.apache.derby#derby;10.5.3.0 in remote-repo
downloading http://127.0.0.1:8081/artifactory/repo/org/apache/derby/derby/10.5.3.0/derby-10.5.3.0.jar ...
[SUCCESSFUL ] org.apache.derby#derby;10.5.3.0!derby.jar (388ms)
$ grape resolve org.apache.derby derby 10.5.3.0
/home/alex/.groovy/grapes/org.apache.derby/derby/jars/derby-10.5.3.0.jar
$ groovy file_parser.groovy records.txt csv
Caught: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at film_parser.run(film_parser.groovy:16)
$ groovy -cp /home/alex/.groovy/grapes/org.apache.derby/derby/jars/derby-10.5.3.0.jar file_parser.groovy records.txt csv
Inserted 1 rows.
Run Code Online (Sandbox Code Playgroud) 我正在处理一个示例 Ruby/Grape 示例,除了 json 被转义外,一切正常。我也是全新的 ruby 及其框架(仅 3 天),如果这个问题是补救性的,那么很抱歉,并提前感谢您
我相当肯定不应该对引号进行转义,无论如何这里是转义的输出:
"{\"word\":\"test\",\"sentiment\":\"unkown\"}"
Run Code Online (Sandbox Code Playgroud)
我的代码
require 'rubygems'
require 'grape'
require 'json'
class SentimentApiV1 < Grape::API
version 'v1', :using => :path, :vendor => '3scale'
format :json
resource :words do
get ':word' do
{:word => params[:word], :sentiment => "unkown"}.to_json
end
post ':word' do
{:word => params[:word], :result => "thinking"}.to_json
end
end
resource :sentences do
get ':sentence' do
{:sentence => params[:sentence], :result => "unkown"}.to_json
end
end
end
Run Code Online (Sandbox Code Playgroud)
配置文件
$:.unshift "./app"
需要'sentimentapi_v1.rb'
运行 SentimentApiV1
包和版本
C:\Ruby-Projects\GrapeTest>bundle install …Run Code Online (Sandbox Code Playgroud) 我目前正在构建一个 API 来访问特定所有者的博客上的所有帖子。我想在博客模型下将它们显示为嵌套的 json。
class API < Grape::API
format :json
prefix "api"
resource "posts" do
get ':id' do
owner = Owner.find(params[:id])
present owner.blogs.each do |b|
present b
b.posts.each do |p|
present p
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
可以安全地假设所有者拥有许多博客,进而拥有许多帖子。
我希望有人解释为什么在Rails(4.1.8)和Grape(0.10.1)中发生这种情况
所以这是我的API:
app/api/root.rb:
module API
class Root < Grape::API
prefix 'api'
mount API::V1::Root
end
end
Run Code Online (Sandbox Code Playgroud)
app/api/v1/root.rb:
module API::V1
class Root < Grape::API
version 'v1'
mount API::V1::Users
end
end
Run Code Online (Sandbox Code Playgroud)
app/api/v1/users.rb:
module API::V1
class Users < Grape::API
format 'json'
resource :users do
desc "Return list of users"
get '/' do
User.all
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
config/routes.rb:
Rails.application.routes.draw do
mount API::Root => '/'
end
Run Code Online (Sandbox Code Playgroud)
在我的application.rb添加中:
config.paths.add "app/api", glob: "**/*.rb"
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
Run Code Online (Sandbox Code Playgroud)
在那种情况下,我收到错误: NameError: uninitialized constant API …