小编Aus*_*tin的帖子

nil的未定义方法`cache':升级到rails 4.2.5.1后的NilClass

从rails升级4.2.5到最近发布的时候4.2.5.1,我遇到了这个错误.此错误仅适用于具有before_filter呈现无效状态的规范,例如render file: "public/422", status: :unauthorized.我对ruby-2.2.2和ruby-2.3.0都有这个错误

action_view解析器方法中存在错误,暗示@cache值为nil.但是,在initialize方法中应该实例化:@cache = Cache.new

我仍然在研究一个可重复的样本,但到目前为止,我怎么@cache会失败.

这些是我的test.rb环境中设置的配置变量

config.cache_classes = true
config.eager_load = false

config.serve_static_files   = true
config.static_cache_control = 'public, max-age=3600'

config.consider_all_requests_local       = true
config.action_controller.perform_caching = false

config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false  

config.action_mailer.default_url_options = {
  :host => '127.0.0.1',
  :port => 3000
}

config.action_mailer.delivery_method = :test
config.active_support.test_order = :random
config.active_support.deprecation = :stderr
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

1) UserController validates user
 Failure/Error: put :update, { …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-4.2

21
推荐指数
1
解决办法
2092
查看次数

使用带单引号,空格,管道等的scala sys.process

我正在尝试使用scala.sys.process._向curron的chronos服务器提交POST请求.因为命令参数中有空格,所以我使用的是Seq[String]变体cmd.!!

我正在构建命令:

val cmd = Seq("curl", "-L", "-X POST", "-H 'Content-Type: application/json'", "-d " + jsonHash,  args.chronosHost + "/scheduler/" + jobType)
Run Code Online (Sandbox Code Playgroud)

如预期的那样产生

cmd: Seq[String] = List(curl, -L, -X POST, -H 'Content-Type: application/json', -d '{"schedule":"R/2014-02-02T00:00:00Z/PT24H", "name":"Scala-Post-Test", "command":"which scalac", "epsilon":"PT15M", "owner":"myemail@thecompany.com", "async":false}', localhost:4040/scheduler/iso8601)
Run Code Online (Sandbox Code Playgroud)

然而,运行这个似乎破坏了这个'Content-Type: application/json'论点:

scala> cmd.!!
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   264    0   100  100   164   2157   3538 --:--:-- --:--:-- …
Run Code Online (Sandbox Code Playgroud)

curl scala

9
推荐指数
2
解决办法
5863
查看次数

为什么scaladoc说HashMap.toArray返回Array [A]而不是Array [(A,B)]?

我在看toArray哈希映射的定义:

http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.HashMap

它有

toArray: Array[A]
def toArray[B >: (A, B)](implicit arg0: ClassTag[B]): Array[B]
Run Code Online (Sandbox Code Playgroud)

我不太明白这一点 - 第一位说你得到一个数组[A],但第二部分说你得到数组[B]?这些都不是我所期望的 - 数组[(A,B)]

当我自己检查时:

scala> val x = scala.collection.mutable.HashMap[String, Int]()
x: scala.collection.mutable.HashMap[String,Int] = Map()

scala> x.put("8", 7)
res0: Option[Int] = None

scala> x foreach println
(8,7)

scala> x.toArray
res2: Array[(String, Int)] = Array((8,7))
Run Code Online (Sandbox Code Playgroud)

为什么不喜欢toList?

toList: scala.List[(A, B)]
Run Code Online (Sandbox Code Playgroud)

scala scaladoc

5
推荐指数
1
解决办法
321
查看次数

在Mac上阻止GPG密码提示

我正在尝试为Github生成一个gpg,如下所示:https//help.github.com/articles/generating-a-new-gpg-key/

我已经生成密钥并设置〜/ .gitconfig和我的本地.git / config包括

[user]
  email = austin@my_email_address.com
  name = Austin Gibbons
  signingkey = <key_id>
[gpg]
  program = /usr/local/bin/gpg
[commit]
  gpgsign = true
Run Code Online (Sandbox Code Playgroud)

在〜/ .gnupg / gpg.conf中,我有

no-emit-version
use-agent
Run Code Online (Sandbox Code Playgroud)

并在〜/ .gnupg / gpg-agent.conf中

default-cache-ttl 28800000
max-cache-ttl 28800000
use-standard-socket
pinentry-program /usr/local/MacGPG2/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac
Run Code Online (Sandbox Code Playgroud)

每次运行时git commit,系统都会提示我输入我的gpg密码,而我设置的内容似乎都没有改变。我不确定如何在钥匙圈中进行设置,不胜感激!

我正在运行gpg-agent守护程序

$ ps aux | grep gpg
austin          63896   0.9  0.0  2432772    676 s010  S+    2:37PM   0:00.00 grep gpg
austin          98503   0.0  0.0  2436440    584   ??  S    10:41AM   0:00.00 /bin/bash /usr/local/MacGPG2/libexec/shutdown-gpg-agent
austin …
Run Code Online (Sandbox Code Playgroud)

git gnupg

5
推荐指数
1
解决办法
3179
查看次数

使用scala.math.max减少Float数组

我对以下行为感到困惑 - 为什么使用math.max减少一个Int数组,但是一个Float数组需要一个包装函数?我记得这不是2.9的问题,但我不能完全确定.

$ scala -version
Scala code runner version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL

$ scala

scala> import scala.math._

scala> Array(1, 2, 4).reduce(max)
res47: Int = 4

scala> Array(1f, 3f, 4f).reduce(max)
<console>:12: error: type mismatch;
 found   : (Int, Int) => Int
 required: (AnyVal, AnyVal) => AnyVal
          Array(1f, 3f, 4f).reduce(max)
                                   ^

scala> def fmax(a: Float, b: Float) = max(a, b)
fmax: (a: Float, b: Float)Float

scala> Array(1f, 3f, 4f).reduce(fmax)
res45: Float = 4.0
Run Code Online (Sandbox Code Playgroud)

更新:这确实有效

scala> Array(1f, 2f, 3f).reduce{(x,y) => math.max(x,y)} …
Run Code Online (Sandbox Code Playgroud)

scala scala-2.10

4
推荐指数
1
解决办法
1992
查看次数

使用HttpURLConnection提交JSON POST请求

我正在尝试使用Scala中的HttpURLConnection提交json发布请求。我遵循了两个教程,并制作了:

def sendPost(url: String, jsonHash: String) {
  val conn: HttpURLConnection = new URL(url).openConnection().asInstanceOf[HttpURLConnection]
  conn.setRequestMethod("POST")
  conn.setRequestProperty("Content-Type", "application/json")
  conn.setRequestProperty("Accept", "application/json")
  conn.setDoOutput(true)
  conn.connect()

  val wr = new DataOutputStream(conn.getOutputStream)
  wr.writeBytes(jsonHash)
  wr.flush()
  wr.close()

  val responseCode = conn.getResponseCode

  println("Sent: " + jsonHash + " to " + url + " received " + responseCode)

  val in = new BufferedReader(new InputStreamReader(conn.getInputStream))
  var response: String = ""
  while(response != null) {
    response = in.readLine()
    println(response)
  }
  in.close()
}
Run Code Online (Sandbox Code Playgroud)

它响应:

Sent: '{"schedule":"R/2014-02-02T00:00:00Z/PT24H", "name":"Scala-Post-Test", "command":"which scalac", "epsilon":"PT15M", "owner":"myemail@thecompany.com", "async":false}' to …
Run Code Online (Sandbox Code Playgroud)

java json curl scala httprequest

1
推荐指数
1
解决办法
1万
查看次数